Copied to clipboard

Flag this post as spam?

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


  • Jon 53 posts 127 karma points
    Jan 22, 2021 @ 16:16
    Jon
    0

    Issue with PartialView in Surface Controller going to /umbraco/surface/

    Hi,

    I have a Surface Controller that posts to an API from an Ajax.BeginForm.

    The Post successfully goes to the Surface controller and posts to the API but when I want to return to a Thank you page it takes me to a XXXX/umbraco/surface/XXX url and the page is white - it is the correct cshtml page as the result is shown - it is just the wrong URL and the Partial page is not inside the parent page.

    I'm using the following:

         [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult SubmitForm(MyModel model)
        {
            bool success = false;
            if (ModelState.IsValid)
            {
                success = SubmitFormToAPI(model);
            }
    
            IPublishedContent vacancyPage = UmbracoContext.Content.GetById(preview: false, model.VacancyFormId);
    
            var successMessage = vacancyPage.Value<IHtmlString>(alias: "successMessage");
            var errorMessage = vacancyPage.Value<IHtmlString>(alias: "errorMessage");
    
            return PartialView("~/Views/Partials/MyVacancy/Result.cshtml", success ? successMessage : errorMessage);
    
        }
    

    I have tried with and without [HTTPPOST]

    I call the form from the parent page like:

     @{ Html.RenderAction("RenderForm", controllerName: "MyVacancySurface");}
    

    Which inherits the following:

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<ContentModels.MyVacancy>
    @using ContentModels = Umbraco.Web.PublishedModels;
    @using MyVacancyPage = Umbraco.Web.PublishedContentModels;
    

    Any ideas?

    Thanks

    Jon

    And my Ajax.BeginForm looks like:

     @using (Ajax.BeginForm("SubmitForm", "MyVacancySurface", new AjaxOptions()
    {
        UpdateTargetId = "form-result",
        HttpMethod = "POST",
        InsertionMode = InsertionMode.Replace,
        OnSuccess = "registerForm.showResult",
        OnFailure = "registerForm.showResult"
    }, new { id = "vacancy-form" }))
    {
        @Html.HiddenFor(expression: m => m.VacancyFormId)
        @Html.ValidationSummary(true)
        @Html.AntiForgeryToken()
    
        <div id="FormPanel" class="well">
    
  • Huw Reddick 274 posts 857 karma points
    Jan 22, 2021 @ 17:43
    Huw Reddick
    0

    What does your onsuccess function do? Since you are using Ajax, your onsuccess function should render the view that was returned

  • Jon 53 posts 127 karma points
    Jan 23, 2021 @ 15:32
    Jon
    0

    Hi, it just hides and shows the form I can't seem to return back to the form page from the controller. Can I return a different method?

  • Huw Reddick 274 posts 857 karma points
    Jan 25, 2021 @ 10:59
    Huw Reddick
    0

    in your onsuccess function you need to set the html of some element to the data (partial view) that is returned by the form.

    Ajax forms return to the form, so you should either set an updatetargetid where the form will display it's reult or process the returned data in the onsuccess.

Please Sign in or register to post replies

Write your reply to:

Draft