开发者

mvc3 Routes setup as id, id2 id3

开发者 https://www.devze.com 2023-03-16 19:43 出处:网络
I have the following area routes setup. context.MapRoute( \"Admin_default3\", \"Admin/{controller}/{action}/{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 { a开发者_如何学Cction = "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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消