【发布时间】:2011-11-12 02:00:37
【问题描述】:
我有一个 MVC3 应用程序,基于 VS 2010 的默认布局,我将其更改为如下图所示
子菜单区域在_layout.cshtml中定义为
<div id="sidebar">
<h3>Entities</h3>
<p></p>
<ul>
@Html.Partial("_EntitiesMenu")
</ul>
</div>
<section id="main">
@RenderBody()
</section>
并且 _EntitiesMenu 包含以下条目
<li>@Html.ActionLink("Addresses", "Index", "Address")</li>
<li>@Html.ActionLink("Applications", "Index", "Application")</li>
我有一个 MapRoute 定义为
routes.MapRoute("Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
{ controller = "Home", action = "Index", id = UrlParameter.Optional });
我所有从菜单开始的实体控制器都在控制器中定义标准,在视图中定义视图。
我需要更改应用程序以使用如下布局
当用户点击实体时,应用应该导航到 myapp/entities/ 或 myapp/entities/index 并且应该在主工作区打开一个视图,如下所示
然后,当用户单击右侧子菜单时,URL 应类似于 myapp/entities/entity1/index、myapp/entities/entity1/edit/1 等(与现在完全一样,但“在”实体页面下。
我将实体控制器定义为
public class EntitiesController : Controller
{
public ActionResult Index()
{ return View();}
}
它的视图看起来像
<div id="workarea">
// here should became new Body region, to load all views called from the other controllers
// something like @RenderBody(), but this don't works
</div>
<div id="sidebar">
<h3>Entities</h3>
<ul>
@Html.Partial("_EntitiesMenu")
</ul>
</div>
我不想对实体控制器或视图进行更改(或在绝对必要时进行最小更改,因为它们有很多)。我可以在实体范围内以某种方式将该区域指定为主体吗?如果用户点击顶部 Home / About,它会从 _layout.cshtml 中“卸载” EntitiesView?
不确定我的问题是否很清楚,但我希望有人能理解我的目标。
谢谢
【问题讨论】:
标签: asp.net-mvc-3 asp.net-mvc-routing asp.net-mvc-3-areas