好的,我想出了如何使用双控制器设置来完成这项工作。
NavigationController 处理 ajax 调用并返回部分视图(注意没有“索引”)
public class NavigationController : Controller
{
public PartialViewResult Home()
{
return PartialView("Home", null);
}
public PartialViewResult About()
{
return PartialView("About", null);
}
...
}
单独的 PermalinkController 通过返回整个常规视图来处理永久链接(注意这有一个“索引”但没有“主页”:
public class PermalinkController : Controller
{
public ActionResult Index()
{
return View();
}
public ActionResult About()
{
return View();
}
...
}
路线:
routes.MapRoute(
"PermalinkRouter",
"{action}",
new { controller = "Permalink", action = "Index" },
new { }
);
routes.MapRoute(
"NavigationRouter",
"Navigation/{action}/{id}",
new { controller = "Navigation", action = "Home", id = UrlParameter.Optional },
new { }
);
意见:
~/Views/Shared/_Layout.cshtml:
...
<header></header>
<div id="pageViewContainer">
@RenderBody()
</div>
<footer></footer>
...
~/Views/Navigation/Home.cshtml 部分视图:
<div> Home Content </div>
~/Views/Permalink/Index.cshtml 视图:
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
@Html.Partial("~/Views/Navigation/Home.cshtml", null)