Setting ViewContext.ViewData.TemplateInfo.HtmlFieldPrefix
will prepend all name
and id
attributes.
I'm wondering if there is a way to prefix just the id
and leave the name
alone.
The scenario is this: A partial view is being loaded by AJAX multiple times on a page. A JavaScript library we are using requires the use of id
s but we also want to be able to post the forms (so the name
s need to match the server model).
Our current solution is to generate a unique number for each time the partial view is loaded, set the HtmlFieldPrefix
to items[n]
(where n
is the generated number) and for our action to recieve an array of items
(where we only need to receive one). This gives us a globally unique id
and a name
which can be parsed by the model binder.
This feels ugly, though. Any suggestions?