_ViewStart.cshtml
@{
Layout = Request.IsAjaxRequest() ? null : "~/Views/Shared/_Layout.cshtml";
}
_Layout.cshtml
...
</head>
<body>
<div id="NavigationPanel">
@{ AjaxOptions options = new AjaxOptions
{
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "ContentPanel",
OnBegin = "OnBeginAnimateContentPanel",
OnComplete = "OnCompleteAnimateContentPanel",
};}
<div>
<p>@Ajax.ActionLink("Users", "Index", "User", options)</p>
<p>@Ajax.ActionLink("Groups", "Index", "Group", options)</p>
<p>@Ajax.ActionLink("Permissions", "Index", "Permission", options)</p>
</div>
</div>
<div id="ContentPanel">
@RenderBody()
</div>
</body>
</html>
全球.Asax.cs
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Main", action = "Index", id = UrlParameter.Optional }
);
}
MainController.Index 动作:
public ActionResult Index()
{
return View();
}
主视图索引.cshtml
@{
ViewBag.Title = "Test-Index";
}
this is the Index View of the MainController
用户/组/权限控制器的索引视图 + 操作类似于 MainController 的索引。为 ViewBag 和一些小测试文本设置了标题。
这里有一个问题。
每个视图(用户/组/权限)的标题永远不可见,尽管当我单击其中一个 Ajax.ActionLInks 时视图在#ContentPanel 中正确呈现...但是当我检查 html 源代码时:
ContentPanel 中的内容是索引视图中的内容???
为什么会这样?如何为每个 Ajax.ActionLink 设置 View 的标题?
<body>
<div id="NavigationPanel">
<p><a data-ajax="true" data-ajax-begin="OnBeginAnimateContentPanel" data-ajax-complete="OnCompleteAnimateContentPanel" data-ajax-mode="replace" data-ajax-update="#ContentPanel" href="/User">Users</a></p>
<p><a data-ajax="true" data-ajax-begin="OnBeginAnimateContentPanel" data-ajax-complete="OnCompleteAnimateContentPanel" data-ajax-mode="replace" data-ajax-update="#ContentPanel" href="/Group">Groups</a></p>
<p><a data-ajax="true" data-ajax-begin="OnBeginAnimateContentPanel" data-ajax-complete="OnCompleteAnimateContentPanel" data-ajax-mode="replace" data-ajax-update="#ContentPanel" href="/Permission">Permissions</a></p>
</div>
<div id="ContentPanel">
this is the text within the Index View of the MainController
</div>
</body>