How can I write the following in MVC?
<input type="text" name="ProjectList[' + count++ + '].ID" value = ' + value + ' />
How can I write the following in MVC?
<input type="text" name="ProjectList[' + count++ + '].ID" value = ' + value + ' />
<%= Html.TextBox("ProjectList[" + (count++) + "].ID",
value, new { @class = "css" }) %>
Use code expressions in <%= ... %>
block in the attributes.
<input type="text" name="<%= ProjectList[count++].ID %>" value = ' + value + ' />
If the value
is meant to be another property of the ProjectList
item... then setting a local variable would be easier:
<% var item = ProjectList[count++].ID; %>
<input type="text" name="<%= item.ID %>" value = '<%= item.value %>' />
Albeit that the HTML helpers (see other answer) provides a better approach.
NB. In .NET 4 prefer <%: ... %>
to ensure things are HTML Encoded.