【发布时间】:2013-10-31 18:48:43
【问题描述】:
在我的 ASP.Net MVC 4 项目中,我在控制器文件夹的子文件夹中有一个控制器-
/Controllers
/GroupA
/AbcController.cs
在 AbcController 中,我有两种方法-
public ActionResult Index()
{
return View();
}
public ActionResult Edit(string value)
{
ViewBag.Message = value;
return View();
}
RouteConfig.cs -
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "TestRoute",
url: "GroupA/{controller}/{action}/{id}",
defaults: new { controller = "AbcController", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
但是当我浏览http://localhost:2240/groupa/abc/edit/somevalue
, 'somevalue' 没有传递给方法。它显示为空。
我在这里缺少什么?
【问题讨论】:
-
如果我没记错的话,是不是通过
.../groupa/abc/edit?somevalue作为 url 或将public ActionResult Edit(string value)更改为public ActionResult Edit(string id)来解决它,即您在路由中将参数命名为id,但value在方法中 -
MVC Areas 将为您的路线(“子文件夹”)提供另一个层次结构。
-
@Jasen,是的,MVC
Area是要走的路。之前我也用过OP的方式,但是最近才知道Areas,非常好用。
标签: asp.net-mvc-4