Copied to clipboard

Flag this post as spam?

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


  • Anders 4 posts 75 karma points
    Mar 25, 2019 @ 07:43
    Anders
    0

    BeginUmbracoForm, how to route to right action

    I'm trying to submit my form to "NewCustomer" action in "CustomerListApiController"

    This is where I'm trying to route my form

    Html.BeginUmbracoForm("NewCustomer", "CustomerListApi",  FormMethod.Post, new { @enctype = "multipart/form-data")
    

    I have a button of type="submit"

    When you click the "Open form" button on my page an Ajax-post is triggered to the "Modal" Action in "CustomerListApiController". The method returns the requested data and a modal with the form is shown on the page. But when I inspect the form element it says that it wants to post to "Modal" action again. Despite that I've specified "NewCustomer" in BeginUmbracoForm.

    My controller

    public class PatientListApiController : SurfaceController
    {
    
    [HttpPost]
            public ActionResult NewCustomer(CustomerBE pCustomerBE)
            {
                 //Do Stuff
    }
    
    [HttpPost]
            public PartialViewResult Modal(int? Id)
            {
                 //GetData and return model for rendering the form in a modal
    
            }
    }
    

    What I'm I doing wrong?

  • AddWeb Solution Pvt. Ltd 89 posts 329 karma points
    Mar 25, 2019 @ 08:03
    AddWeb Solution Pvt. Ltd
    1

    Your controller has 2 methods, 1 for showing the form ShowForm and 1 for the business logic that is executed after the submit button is pressed HandleFormPost

    All the routing information is in the following statement

    Html.BeginUmbracoForm

    Html.BeginUmbracoForm is only a wrapper around Razors own Html.BeginForm with some additional functionality for routing.

    The above statement creates something like

    For more explanation on creating a form using MVC, check out this article

    https://blog.michaelckennedy.net/2012/01/20/building-asp-net-mvc-forms-with-razor/

  • 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