I\'m trying to load a partial view into a div from a calling view, however the partial view loads into a new page. There isn\'t much code to it and I\'ve tried various ways
Your partial needs to be within the ajax form
Couple of remarks about your code:
Ajax.*
helpers in ASP.NET MVC 3 RC2 no longer use MS AJAX which has been deprecated in favor of jQuery, so your script inclusions are wrong. You need to include jquerySo your code might look something among the lines:
<script src="@Url.Content("~/scripts/jquery-1.4.4.js")" type="text/javascript"></script>
@Ajax.ActionLink("Save", "Test", "Home", new AjaxOptions {
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "mydiv"
})
<div id="mydiv">
@Html.Partial("Test")
</div>
I think you should use <input type="submit" />
instead of @Ajax.Actionlink(...)
in MVC4 you can add bundle @Scripts.Render("~/bundles/jqueryval")
just after @Scripts.Render("~/bundles/jquery")
or add script reference in script section in page view as shown below:
@section scripts
{
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script>
}
Good Luck.
Add this line to your page (master page or layout)
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script>
just after MicrosoftMvcAjax.js line.