Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • Anders Brännmark 226 posts 277 karma points
    Jun 06, 2013 @ 14:07
    Anders Brännmark

    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?


  • Anders Brännmark 226 posts 277 karma points
    Jun 06, 2013 @ 16:55
    Anders Brännmark

    The answer is to prefix the model on the controller and on the EditorFor:


    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.

Please Sign in or register to post replies

Write your reply to: