Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It's bad practice to put javascript code in views, let alone partial views. So I would recommend you to externalize this javascript code in a separate function in a separate javascript file.</p> <p>And then you could subscribe to the <code>OnSuccess</code> event of the Ajax.BeginForm helper:</p> <pre><code>@using (Ajax.BeginForm("Edit", "Home", new AjaxOptions { OnSuccess = "editSuccess", UpdateTargetId = "content", InsertionMode = InsertionMode.Replace })) { ... } </code></pre> <p>and then define the <code>editSuccess</code> function in a <strong>separate</strong> javascript file:</p> <pre><code>function editSuccess(result) { alert('hi'); } </code></pre> <p>now in your partial view you should leave only what is supposed to be in a partial - markup. Get rid of any <code>&lt;script&gt;</code> tags, you don't need them. You don't need any inline scripts. They only increase the size of your webpages and waste bandwidth as they cannot be cached by the browsers:;</p> <pre><code>@model Test.Models.CARE &lt;h2 style="padding: 0px; margin-top: 0px;"&gt;Edit&lt;/h2&gt; @using (Html.BeginForm("SaveForConfirmation", "Home")) { ... } </code></pre> <hr> <p>UPDATE:</p> <p>If you have some poorly written javascript that depends on crap like ViewBag inside the partial then you could invoke the corresponding function from within the OnSuccess callback:</p> <pre><code>@using (Ajax.BeginForm("Edit", "Home", new AjaxOptions { OnSuccess = "s", UpdateTargetId = "content", InsertionMode = InsertionMode.Replace })) { ... } </code></pre> <p>Notice how I have defined <code>OnSuccess = "s"</code> where <code>s</code> is the function that you have defined in your partial and which will be invoked in this case. But I repeat once again, this is a wrong approach and should only be used if you don't have time to refactor your code properly.</p>
 

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