I would like to add an index into mvchtmlstring because I use it in a table. If I need to get the whole list of the data input by user, I need an index so that the system are able to get all the list of data. So this is the example code that I want for:
@Html.CommonTextBoxFor(m => m.sample.RefNo, new { @class = "noMarginBottom", Name+="[0]" })
The point is I want something like this Name+="[0]"
I wish to get back the same name but adding a index after the name. So the name in the html will be like "name=m.sample.RefNo[0]".
Thanks for the help.
Sounds like you're after the NameFor helper. You'd use it like so:
Seems like you have a mismatch between your view model and your controller code, though, if you need to do this - if
RefNo
should be indexed, the property should be a collection of some sort, so manually building the name attribute wouldn't be necessary.