mvc3 路由设置为 id, id2 id3
我有以下区域路线设置。
context.MapRoute(
"Admin_default3",
"Admin/{controller}/{action}/{id}/{id2}/{id3}",
new { action = "Index" }
);
context.MapRoute(
"Admin_default2",
"Admin/{controller}/{action}/{id}/{id2}",
new { action = "Index"}
);
context.MapRoute(
"Admin_default",
"Admin/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional }
);
当控制器操作被点击时,我会执行如下操作,将参数放入可读的变量名称中。
public ActionResult Search(Guid? id, int? id2, bool? id3)
{
Guid? source = id;
int daysOld = id2;
bool includeNonEnglish = id3;
//.... Action!
}
我应该继续这样吗?我应该创建过多的路线吗?
谢谢
I have the following area routes setup.
context.MapRoute(
"Admin_default3",
"Admin/{controller}/{action}/{id}/{id2}/{id3}",
new { action = "Index" }
);
context.MapRoute(
"Admin_default2",
"Admin/{controller}/{action}/{id}/{id2}",
new { action = "Index"}
);
context.MapRoute(
"Admin_default",
"Admin/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional }
);
When a controller action is hit I do something like the following where I place the params into readable variable names.
public ActionResult Search(Guid? id, int? id2, bool? id3)
{
Guid? source = id;
int daysOld = id2;
bool includeNonEnglish = id3;
//.... Action!
}
Should I continue that way? Should I create a plethora of routes?
thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会创建更多路线。这样,您就可以得到如下内容:
而不是: 除
其他外(例如使用 jQuery 进行 AJAX 调用,您使用 Json 来指定参数)。它会让事情变得更具可读性。如果您正在使用或打算使用 T4MVC,它也会有所帮助。
I would create more routes. That way, you have things like:
Instead of:
Among other things (like AJAX calls with jQuery, where you use Json for specifying parameters). It would make things more readable. It would also help if you're using, or going to use, T4MVC.