MVC3路线设置为ID,ID2 ID3 [英] mvc3 Routes setup as id, id2 id3

查看:184
本文介绍了MVC3路线设置为ID,ID2 ID3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的区域内路由设置。

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 }
);

当一个控制器动作被击中我做这样的事情,我放置PARAMS成可读的变量名以下。

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?

感谢您

推荐答案

我会创造更多的途径。这样的话,你有这样的话:

I would create more routes. That way, you have things like:

Html.ActionLink(title, "Action", "Controller", new { source = <value>, daysOld = <value>, includeNonEnglish = <value> });

而不是:

Html.ActionLink(title, "Action", "Controller", new { id = <value>, id2 = <value>, id3 = <value> });

在其他方面(如AJAX使用jQuery,您使用JSON用于指定调用的参数)。这会使事情更易读。这也将有助于如果您正在使用或打算使用,T4MVC。

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.

这篇关于MVC3路线设置为ID,ID2 ID3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆