Copied to clipboard

Flag this post as spam?

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


  • Cimplex 113 posts 576 karma points
    Mar 24, 2016 @ 12:24
    Cimplex
    0

    Modelstate errors and inputvalues displayed on all forms on the same page

    Hi! I have multiple forms on the same page that uses the same model with dataannotations, my problem is when im submitting one of the forms to a surfacecontroller and using "return CurrentUmbracoPage()" all forms on the page gets the entered values, it also displays the modelstate errors on all forms.

    Is it a way around this?

    Controller:

    [ChildActionOnly]
    public ActionResult Index()
    {
        return PartialView("_ContactForm", new ContactInput());
    }
    
    [HttpPost]
    public ActionResult Submit(ContactInput model)
    {
        if (!ModelState.IsValid)
            return CurrentUmbracoPage();
    
        return RedirectToCurrentUmbracoPage();
    }
    

    Model:

    public class ContactInput
    {
        [Required]
        public string Name { get; set; }
    
        [Required]
        public string Email { get; set; }
    }
    

    View:

    @Html.Action("Index", "Contact")
    @Html.Action("Index", "Contact")
    

    Form:

    @using (Html.BeginUmbracoForm<ContactController>("Submit"))
    {
        <div>
            <p>Name</p>
            @Html.TextBoxFor(x => x.Name)
        </div>
        <div>
            <p>Email</p>
            @Html.TextBoxFor(x => x.Email)
        </div>
    
        <input type="submit"/>
    }
    

    I do know i can solve this using begin ajaxform but i want to use the normal post.

    Thanks in advance!

  • Cimplex 113 posts 576 karma points
    Mar 28, 2016 @ 07:49
    Cimplex
    0

    Up ^

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies