html.hiddenfor

Html.HiddenFor value property not getting set

醉酒当歌 提交于 2019-11-27 02:31:47
问题 I could have used @Html.HiddenFor(x=> ViewData["crn"]) but, I get, <input id="ViewData_crn_" name="ViewData[crn]" type="hidden" value="500" /> To somehow circumvent that issue( id=ViewData_crn_ and name=ViewData[crn] ), I tried doing the following, but the "value" attribute isn't getting set. @Html.HiddenFor(x => x.CRN, new { @value="1"}) @Html.HiddenFor(x => x.CRN, new { @Value="1"}) generates <input id="CRN" name="CRN" type="hidden" value="" /> <input Value="500" id="CRN" name="CRN" type=

What does Html.HiddenFor do?

夙愿已清 提交于 2019-11-26 20:10:31
Although I have read the documentation on Html.HiddenFor, I've not grasped what is it used for... Could somebody explain its uses and give a short example? Where should those helpers go in the code? Justin Niessner It creates a hidden input on the form for the field (from your model) that you pass it. It is useful for fields in your Model/ViewModel that you need to persist on the page and have passed back when another call is made but shouldn't be seen by the user. Consider the following ViewModel class: public class ViewModel { public string Value { get; set; } public int Id { get; set; } }

ASP.Net MVC Html.HiddenFor with wrong value

可紊 提交于 2019-11-26 12:06:28
I'm using MVC 3 in my project, and I'm seeing a very strange behavior. I'm trying to create a hidden field for a particular value on my Model, the problem is that for some reason the value set on the field does not correspond to the value in the Model. e.g. I have this code, just as a test: <%:Html.Hidden("Step2", Model.Step) %> <%:Html.HiddenFor(m => m.Step) %> I would think that both hidden fields would have the same value. What I do is, set the value to 1 the first time I display the View, and then after the submission I increase the value of the Model field by 1. So, the first time I

ASP.Net MVC Html.HiddenFor with wrong value

﹥>﹥吖頭↗ 提交于 2019-11-26 02:50:24
问题 I\'m using MVC 3 in my project, and I\'m seeing a very strange behavior. I\'m trying to create a hidden field for a particular value on my Model, the problem is that for some reason the value set on the field does not correspond to the value in the Model. e.g. I have this code, just as a test: <%:Html.Hidden(\"Step2\", Model.Step) %> <%:Html.HiddenFor(m => m.Step) %> I would think that both hidden fields would have the same value. What I do is, set the value to 1 the first time I display the