当我单击部分视图的任何页面链接时,该相关页面应显示在渲染主体部分中,而无需刷新任何页面。我该怎么办?
答案 0 :(得分:1)
您可以将AJAX帮助程序与不显眼的Ajax结合使用
You can find more information at this page
Microsoft.jQuery.Unobtrusive.Ajax
NuGet软件包<script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>
上包含脚本代码示例
@Ajax.ActionLink("View All Student Info", "AllStudent", "Home", new AjaxOptions
{
UpdateTargetId = "divAllStudent",
OnBegin = "fnOnBegin",
InsertionMode = InsertionMode.Replace,
HttpMethod = "GET",
LoadingElementId = "imgloader",
OnSuccess= "fnSuccess",
Confirm="Do you want to get all student info ?????"
},
new { @class = "btn btn-default" })
代码示例
[HttpGet]
public PartialViewResult AllStudent()
{
using (TempEntities db = new TempEntities())
{
var objAllStudent = db.StudentInfoes.ToList();
return PartialView("AllStudent", objAllStudent);
}
}
选项UpdateTargetId
是HTML ID容器,AJAX结果将在其中放置结果内容。通常您要使用“替换”。您可以将OnBegin和OnSuccess用作执行诸如显示加载器,隐藏加载器等操作的Javascript方法