mvc3 Routes setup as id, id2 id3

不羁的心 提交于 2019-12-01 10:53:54

问题


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


回答1:


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

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

Instead of:

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

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.



来源:https://stackoverflow.com/questions/6541954/mvc3-routes-setup-as-id-id2-id3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!