Note that there are some explanatory texts on larger screens.

plurals
  1. POInsert partial view on current page rather than redirecting
    primarykey
    data
    text
    <p>Basically I'm trying to return a partial view through an AJAX request. The issue is however the fact that the page gets redirected to the partial view rather than replacing the content on the current page.</p> <p>Here's the view where I send the AJAX request:</p> <pre><code>@model MediaProfits.Models.DomainEntities.ProtectedPassword @Scripts.Render("~/Scripts/CustomScripts/LeadChecker.js") @{ ViewBag.Title = "Unlock " + @Model.Name; } &lt;h2&gt;Unlock @Model.Name&lt;/h2&gt; &lt;button onclick="StartCheckingLead('@Model.SubId');"&gt;Start Checking&lt;/button&gt; @using (Ajax.BeginForm("Lead", "Check", new AjaxOptions() { HttpMethod = "get", InsertionMode = InsertionMode.Replace, UpdateTargetId = "password" })) { @Html.HiddenFor(m =&gt; m.SubId) &lt;input type="submit" value="Check For Completion" /&gt; } @Html.Partial("_Password", "") </code></pre> <p>And here is the controller action that returns the partial view:</p> <pre><code>public PartialViewResult Lead(string subId) { var lead = db.Leads.Where(l =&gt; l.SubId == subId); if (lead.ToList().Count &gt; 0) { return PartialView("~/Views/Passwords/_Password.cshtml", "unlocked..."); } else { return PartialView("~/Views/Passwords/_Password.cshtml", ""); } } </code></pre> <p>And here is the partial view (which the page now get's redirected to):</p> <pre><code>@model System.String &lt;div id="password"&gt; &lt;label&gt;Password:&lt;/label&gt; &lt;label&gt;@Model&lt;/label&gt; &lt;/div&gt; </code></pre> <p>Finally here is my BundleConfig.cs file:</p> <pre><code>using System.Web; using System.Web.Optimization; namespace MediaProfits { public class BundleConfig { // For more information on Bundling, visit http://go.microsoft.com/fwlink/?LinkId=254725 public static void RegisterBundles(BundleCollection bundles) { bundles.Add(new ScriptBundle("~/bundles/jquery").Include( "~/Scripts/jquery-{version}.js")); bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include( "~/Scripts/jquery-ui-{version}.js")); bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include( "~/Scripts/jquery.unobtrusive*", "~/Scripts/jquery.validate*")); // Use the development version of Modernizr to develop with and learn from. Then, when you're // ready for production, use the build tool at http://modernizr.com to pick only the tests you need. bundles.Add(new ScriptBundle("~/bundles/modernizr").Include( "~/Scripts/modernizr-*")); bundles.Add(new StyleBundle("~/Content/css").Include("~/Content/site.css")); bundles.Add(new StyleBundle("~/Content/themes/base/css").Include( "~/Content/themes/base/jquery.ui.core.css", "~/Content/themes/base/jquery.ui.resizable.css", "~/Content/themes/base/jquery.ui.selectable.css", "~/Content/themes/base/jquery.ui.accordion.css", "~/Content/themes/base/jquery.ui.autocomplete.css", "~/Content/themes/base/jquery.ui.button.css", "~/Content/themes/base/jquery.ui.dialog.css", "~/Content/themes/base/jquery.ui.slider.css", "~/Content/themes/base/jquery.ui.tabs.css", "~/Content/themes/base/jquery.ui.datepicker.css", "~/Content/themes/base/jquery.ui.progressbar.css", "~/Content/themes/base/jquery.ui.theme.css")); } } } </code></pre> <p>I want the partial view to be inserted on the current page - not redirect to it.</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.
    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