Multiple forms with some property names equal on view models? MVC
Run into a problem.
Need to have multiple forms on a single page, the forms have their own controllers and models. However the models have properties with the same names. As BeginUmbracoForm in the partial view doesnt add any specific controller action on the action tag the validation occurs in both forms even if just one form is submitted.
If I prefix the properties in the models so they become unique it works great. But really I dont want to prefix the model properties in my code as that is insane.
Multiple forms with some property names equal on view models? MVC
Run into a problem.
Need to have multiple forms on a single page, the forms have their own controllers and models. However the models have properties with the same names. As BeginUmbracoForm in the partial view doesnt add any specific controller action on the action tag the validation occurs in both forms even if just one form is submitted.
If I prefix the properties in the models so they become unique it works great. But really I dont want to prefix the model properties in my code as that is insane.
Anyone have a better suggestion for this problem?
The answer is to prefix the model on the controller and on the EditorFor:
Controller:
Public ActionResult MemberForgottenPassword([Bind(Prefix="ForgottenPassword")] ForgottenPassword model)
Partilal View:
@Html.EditorFor(x => Model, "", "ForgottenPassword")
This should be possible to do in regular mvc with a viewdatadictionary on the view also like this:
@Html.Partial("MemberForgottenPassword", new ForgottenPassword(), new ViewDataDictionary { TemplateInfo = new System.Web.Mvc.TemplateInfo { HtmlFieldPrefix = "ForgottenPassword" } })
But, that doesnt work in Umbraco 6.1. So use the editorfor version instead.
is working on a reply...