mvc3 路由设置为 id, id2 id3

发布于 2024-11-17 18:12:30 字数 697 浏览 6 评论 0原文

我有以下区域路线设置。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

つ低調成傷 2024-11-24 18:12:30

我会创建更多路线。这样,您就可以得到如下内容:

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

而不是: 除

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

其他外(例如使用 jQuery 进行 AJAX 调用,您使用 Json 来指定参数)。它会让事情变得更具可读性。如果您正在使用或打算使用 T4MVC,它也会有所帮助。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文