Note that there are some explanatory texts on larger screens.

plurals
  1. POAjax call to update div on failure, or redirect to page on success
    primarykey
    data
    text
    <p><b>Background:</b></p> <p>I have a popup which lets me create a company, this popup has a text field called company name, and this is a required field (using the <code>[Required]</code> data annotation on the backing view model). </p> <pre><code>&lt;div class="popup-editor"&gt; &lt;h4 class="popup-title"&gt; Add new Company&lt;/h4&gt; @using (Ajax.BeginForm("Create", "Company", new AjaxOptions { UpdateTargetId = "popup-editor", OnSuccess = "$.validator.unobtrusive.parse('form');" },)) { @Html.ValidationSummary(true); &lt;table&gt; &lt;tr&gt; &lt;td class="label"&gt; Company Name &lt;/td&gt; &lt;td class="editor-field"&gt; @Html.EditorFor(x =&gt; x.Name) @Html.ValidationMessageFor(x =&gt; x.Name) &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;div class="popup-buttons"&gt; &lt;a href="#" onclick="return togglePopupEditor();"&gt;Cancel&lt;/a&gt; &lt;input type="submit" value="Add Company" /&gt; &lt;/div&gt; } &lt;/div&gt; </code></pre> <p>Now the validation works correctly and the ajax lets me show an error message in the popup when the name field is empty.</p> <p><b>Problem:</b></p> <p>When there are no validation errors I need to be able to redirect to a new page (company details page), but instead this page is inserted into the div where the popup contents were. For example:</p> <pre><code>public ActionResult Create(CreateCompanyModel model) { if(!ModelState.IsValid) { return PartialView("_AddCompanyEditor"); } Company c = CompanyService.Create(model.Name); return RedirectToAction("Details", new { companyId = c.Id }); } </code></pre> <p>Is there any way to either; force a complete redirect for the entire page, or switch to a standard HTML form?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload