I have a form that creates a number of checkbox elements using Razor code like this
foreach (var tag in Model.Tags)
{
<input type="checkbox" id="@tag.ID" name="@tag.ID" value="@tag.TagName"/>@tag.TagName<br /
}
This works but I want the ID's and names to be in this format chkTag[TagID] I've tried this
<input type="checkbox" id="[email protected]" name="[email protected]" value="@tag.TagName"/>
but Razor just treats the whole thing as string and names them [email protected].
So I guess my question is how do I add the dynamic razor ID to the end of my Name and ID's?
Thanks
Html.CheckBoxFor, and specify thenamehtml attribute? and furthermore, use an editor template and save theforeachloop.