user7809040
user7809040

Reputation:

input hidden value doesn't send to controller

I'm trying post to my database,everything what i want i can get from my formcollection and my table but input hidden value.My main view is using @model List

Here is my code this my modal popup

@using (Html.BeginForm("update3", "UpdateInfo", FormMethod.Post))
{

<div class="modal fade" role="dialog" id="mymodal">



    <form id="stok_formu">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">


                <div class="modal-header">
                    <button class="close" type="button" data-dismiss="modal">&times;</button>



                </div>
                <div class="modal-body" id="modal2">

                    <div class="row">
                        <label for="names" id="name" name="name"></label>
                        <input type="hidden" id="names" name="names" />
                        
                   
                    </div><br />

                    <div class="row">
                        <div class="col-md-3">
                            @Html.Label(" Clothes codes: ")
                        </div>
                        <div class="col-md-3">

                            <input type="number" class="input-sm" id="codes" name="codes" />
                        </div>
                    </div><br />

                    <div class="row">
                        <div class="col-md-3">
                            @Html.Label("New Price : ")
                        </div>
                        <div class="col-md-3">

                            <input type="number" class="input-sm" id="newprice" name="newprice" />
                        </div>
                    </div>


                    <input class="btn btn-success" id="change"  type = "submit" name="change"/>
                </div>


            </div>
        </div>
        </form>
</div>
}

With this javascript code ,i can get my "name" from my table and put on my modal and my problem is begin is here,when i click button submit modal popup doesn't send hidden value to controller but ican get my value of "newprice"

 function metot(x) {
        namee = document.getElementById("tablo2").rows[0].cells.item(0).innerHTML;
        document.getElementById("name").innerHTML = namee;
    }

and table from my main view

 <tbody id="tablo2">


        @foreach(var oge in Model)
        {
            <tr onclick="metot(this)">
                <td>@Html.Encode(oge.name)</td>
                <td id="codes">@Html.Encode(oge.codes)</td>
                <td id="price">@Html.Encode(oge.price)</td>
                <td>
                    <button  id="change" onclick="metot(this)"  type="button" data-toggle="modal" data-target="#mymodal" class="btn btn-warning tab-content"><span>Change</span></button>

                </td>
            </tr>
        }

    </tbody>

Upvotes: 0

Views: 910

Answers (1)

Rhumborl
Rhumborl

Reputation: 16609

You are setting the text of the label with id name, but you aren't setting the value of the hidden field with id names, hence it is not sent when you submit the form. <label> elements do not send data back to the server.

This should work (I assume the variable namee should actually be called urun_adi):

function metot(x) {
    urun_adi = document.getElementById("tablo2").rows[0].cells.item(0).innerHTML;
    document.getElementById("name").innerHTML = urun_adi;
    document.getElementById("names").value = urun_adi;
}

Upvotes: 1

Related Questions