2011-06-01 54 views
4

我有一个真正显示“http:// localhost:3579/MusicStore/StoreManager/Index”的地址“http:// localhost:3579/MusicStore/StoreManager”。在ASP.net中的二级视图MVC

我想从索引到“http:// localhost:3579/MusicStore/StoreManager/Edit”指向同一级别的另一个地址。编辑是StoreManager文件夹内的视图,因此是第二级视图。

我很困惑我甚至会将该方法放入哪个控制器中。我尝试在MusicStoreController中放置“public ActionResult Edit”,但它未被识别。我怎样才能做到这一点?

回答

2

这听起来像你的行为是在正确的地方,但你需要确保有一个路由指定你的网址路由到该行动。确保你的global.asax或区域注册文件中指定了这样的路由,如果你的项目正在使用区域:

context.MapRoute(
       "MusicStore_Edit", 
       "MusicStore/StoreManager/{action}", 
       new { action = "Index"} 
      ); 
+0

好的答案。但是现在它找不到索引视图。它正在查看“〜/ Views/StoreManager/Index.cshtml”。这是因为我将“StoreManager”指定为默认控制器。但是,我希望它在“MusicStore/StoreManager”内寻找视图。 – Andrew 2011-06-01 20:49:06

+0

@Andrew - 您可以在Index操作中指定索引文件正确位置的路径。在方法的'return View()'部分指定正确的路径,例如'return View(“〜/ Areas/Admin/Views/MusicStore/StoreManager/Index.cshtml”)' – amurra 2011-06-01 20:54:21

+0

我希望能减少手动操作。尽管如此,这是有效的。谢谢。 – Andrew 2011-06-01 20:59:37