_ViewStart.cshtml
@{
Layout = Request.IsAjaxRequest() ? null : "~/Views/Shared/_Layout.cshtml";
}
_布局.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>
Global.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
用户/组/权限控制器的索引视图+操作类似于主控制器的索引。标题设置为 ViewBag 和一些小测试文本。
这里有一件事出了问题。
尽管当我单击这些 Ajax.ActionLInks 之一时,视图在 #ContentPanel 中正确呈现,但每个视图(用户/组/权限)的标题永远不可见...但是当我检查 html 源代码时:
ContentPanel 中的内容是索引视图中的内容???
这是为什么?如何为每个 Ajax.ActionLink 设置视图标题?
<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>