The HTML
int i = 1;
foreach (var item in Model.MyDataset)
{
<td class="tdBorder">
@Html.DisplayFor(x => item.ID, new { id = "VisibleID" + @i })
@Html.HiddenFor(x => item.ID, new { id = "HiddenID" + @i })
</td>
i += 1;
}
The jQuery
for (i = 1; i <= rowCount; i++) {
var myID_Visible = $.trim($("#VisibleID" + i).val());
var myID_Hidden = $.trim($("#HiddenID" + i).val());
}
I'm trying to learn some MVC and jQuery.
Would some one explain to me why calling
var myID_Visible = $.trim($("#VisibleID" + i).val());
returns an empty string but
var myID_Hidden = $.trim($("#HiddenID" + i).val());
returns the value of my item.ID?
The only difference is that the first jQuery line refers to a @Html.DisplayFor (returns empty string) while the second jQuery line refers to a @Html.HiddenFor (returns actual value).
Why can't i get a value from the @Html.DisplayFor?