niknaz
niknaz

Reputation: 47

fill @Html.HiddenFor in view

i have a @Html.HiddenFor . i wanna fill it by my td (1234569876) .

how can do it?

           <tr>
                <td valign="top"><strong>Code:</strong></td>
                <td colspan="2" align="right" id="tdPobox">1234569876</td>

            </tr> 


      //i don't know how should i write it
          @Html.HiddenFor(m => m.PostalCode )

Upvotes: 0

Views: 151

Answers (3)

Jatin patil
Jatin patil

Reputation: 4288

The properties of model gets bind with the help of NAME in the html control.

Therefore your approcah should be as follows:

$(function () {
    $("input[name*='PostalCode']").val($("#tdPobox").html());
}

Upvotes: 0

Amit
Amit

Reputation: 15387

If you can use jquery then solution is below:

$(function(){
    $("#PostalCode ").val($("#tdPobox").html());
});

Upvotes: 0

Xavier Malparty
Xavier Malparty

Reputation: 66

The Id of this hidden input should be "PostalCode"

@Html.HiddenFor(m => m.PostalCode )

So by adding some Jquery script, you can dynamicaly get some values from any part of your web page like this :

$(function () {
    // Set the Value of input with the content of td
    $("#PostalCode").val($("#tdPobox").html());
}

Join this part of JavaScript after the implementation of JQuery (generaly the Section Scripts is fine for that) and it should work =)

Upvotes: 2

Related Questions