Copied to clipboard

Flag this post as spam?

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


  • Sasha Kruglyak 10 posts 97 karma points
    Nov 10, 2014 @ 14:09
    Sasha Kruglyak
    0

    Call UmbracoApiController via Ajax.BeginForm

    Hi there,

     

    I have some issue with calling Api controller via Ajax.BeginForm,

     

    form in cshtml (rendering in partial view):

     

     @using (Ajax.BeginForm("/Umbraco/Api/CreateOrganization/CreateNewOrganization", new AjaxOptions { HttpMethod = "POST" }))

            {

     

     

                    @Html.Label("Site Name")

                    @Html.TextBoxFor(m => m.SiteName, new { required = "required" })

     

                        @Html.ValidationMessageFor(m => m.SiteName)

     

     

     

     

     

                    @Html.Label("Site Description ")

                    @Html.TextAreaFor(m => m.Description, 3, 3, null)

     

     

     

     

                   

                    Cancel

     

     

            }

     

    controller:

     

    public class CreateOrganizationController : UmbracoApiController

        {

    [System.Web.Http.HttpPost]

            public void CreateNewOrganization(NewSiteModel organization)

            { /*some code*/}

    }

    but after rendering the page in action form i have path:

     

    form id="form0" action="<strong>/umbraco/RenderMvc/</strong>Umbraco/Api/CreateOrganization/CreateNewOrganization" method="post">          

     

    the issue is /umbraco/RenderMvc/, if i change path on the page to /Umbraco/Api/CreateOrganization/CreateNewOrganization its work fine, is there any idea how can i get right path?

     

    Thanks

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Nov 10, 2014 @ 15:46
    Alex Skrypnyk
    0

    Hi Sasha,

    Try to use like that:

     @using (Ajax.BeginForm("CreateOrganization", "CreateNewOrganization", new AjaxOptions { HttpMethod = "POST" }, new { enctype = "multipart/form-data" }))
    
    {
    }
    
  • Sasha Kruglyak 10 posts 97 karma points
    Nov 11, 2014 @ 09:40
    Sasha Kruglyak
    0

    Hi Alex,

    It did't help.

    Usually i use this form for access SurfaceController, but in this case i want access ApiController

  • Sasha Kruglyak 10 posts 97 karma points
    Nov 11, 2014 @ 10:40
    Sasha Kruglyak
    101

    Ok,

     

    it's look like i found my solution:

     

    @using (Ajax.BeginForm(null, null, new AjaxOptions { HttpMethod = "POST" }, new { @action = "/Umbraco/Api/CreateOrganization/CreateNewOrganization" }))

Please Sign in or register to post replies

Write your reply to:

Draft