簡體   English   中英

MVC RouteLink URL格式

[英]MVC RouteLink URL format

我有以下RouteLink

@Html.RouteLink("Accept Offer", new { controller = "Case", action = "Accept", id = item.CaseId, offerid = item.PxOfferId }, new { @class = "btn btn-success" })

該網址的格式為:

http://localhost:54644/Clients/Case/Accept/15847?offerid=3103

如何將URL格式化為:

http://localhost:54644/Clients/Case/Accept/15847/3103

謝謝。

預設路線:

    context.MapRoute(
        "Clients_default",
        "Clients/{controller}/{action}/{id}",
        new { controller = "Login", action = "Index", id = UrlParameter.Optional }
    );

如果將其放在定義好的路線中,則路線有效:

    context.MapRoute(
        name: "Accept Offer",
        url: "Clients/{controller}/{action}/{id}/{offerid}",
        defaults: new { controller = "Case", action = "Accept", id = 0, offerid = UrlParameter.Optional }
    );

但隨后會在其他頁面上導致錯誤。

你在娘家路由RouteConfig文件App_Start (如果您正在使用MVC3 / 4,然后線路可能會在配置Global.asax文件代替):

routes.MapRoute(
    name: "MyCaseRoute",
    url: "/clients/{controller}/{action}/{id}/{offerId}",
    defaults: new { controller = "Case", action = "Accept", id = UrlParameter.Optional, offerId = UrlParameter.Optional }
);

用法:

@Html.RouteLink("My Link Text", routeName: "MyCaseRoute", routeValues: new { controller = "case", action = "accept", id = 1, offerId = 2 })

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM