We're building a dynamic complex form application. Because of it's complexity (a lot of inheritance and complex types), the names and id's that are generated are big (huge?).
Therefore we would like to modify the way MVC is generating the id and name attributes. I used reflector (and google / stackoverflow) to figure out where that's done:
- Id's are generated using:
ViewData.TemplateInfo.GetFullHtmlFieldId(...)
- Names are generated using:
ViewData.TemplateInfo.GetFullHtmlFieldName(...)
We are using the '...For' build in helper methods to generate labels, textboxes, validation messages, ...
- Here is an example of a generated id:
ZForm_Part_1__Repeater_0__RepeatingPart_0__ContactSelectList_0__PersonData_TelephoneAddress_Number_FormattedNumber
- Here is an example of a generated
name:
ZForm.Part[1].Repeater[0].RepeatingPart[0].ContactSelectList[0].PersonData.TelephoneAddress.Number.FormattedNumber
Since the size and complexity of our forms this adds up to several tens of kilobytes for one form.
Why is it on 1 page? Because it's a requirement ;)
For now I see 2 options how we could change the way these id's are generated. I don't really any of them and was wondering if there's a cleaner way to do what we want?
Here are the options I see:
- Copy/paste the source of the necessary helper methods, including the private InputHelper(...) and modify the InputHelper to call our own version of GetFullHtmlFieldName (is this legal?)
- Write some kind of filter that would hack into the generated html and use some regexp kungfu to filter out all id and name attributes and tranform them to a shorter version.
The end result should generate names like this:
Z.P[1].Rep[0].RP[0].CSL[0].PD.Tel.N.FormattedNumber
I hope I wrote enough details to understand the thing we're after.
Ideal would be if the name / id generating logic would be plugable.
Manu.
ps: It is similar as this question.