我想使用Ajax.PartialView().But加载部分视图,同时尝试部分视图根本没有加载。它正在点击AccountController.Login(),但没有渲染登录页面这是我的代码。
我想在“formbody”div中加载登录页面而不刷新索引页面。请给出建议。
主\ Index.cshtml
@{
ViewBag.Title = "Home Page";
}
@using(Ajax.BeginForm(
new AjaxOptions
{
HttpMethod="GET",
InsertionMode=InsertionMode.Replace,
UpdateTargetId = "formbody"
}
))
{
<div class="pager glyphicon-align-center" id="formbody">
<button type="button" id="login" class="btn btn-default btn-lg">
@Ajax.ActionLink("Login", "Login", "Account", new { id = "login" }, new AjaxOptions { })
<span class="glyphicon glyphicon-log-in"> </span> @*Login*@
</button>
<button type="button" class="btn btn-default btn-lg" onclick="location.href='@Url.Action("Register", "Account", new { id = "Registerlink" })'">
</button>
</div >
}
@section scripts {
@*<script src="/Scripts/jquery-1.8.2.js"></script>*@
@Scripts.Render("~/Scripts/jquery.unobtrusive-ajax.min.js")
<script type="text/javascript">
$("#login").click(function () {
$(".nav-tabs").html("<li> <a href='#Tab1'> Login</a></li>");
});
</script>
}
AccountController.Login
[AllowAnonymous]
public ActionResult Login(string returnUrl)
{
if (Request.IsAjaxRequest())
{
return PartialView("Login");
}
return View();
}
BundleConfig
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js",
"~/Scripts/MicrosoftMvcAjax.js",
"~/Scripts/MicrosoftAjax"));