3

私は MVC 4 が初めてで、カスタム ルーティングに問題があります。URL で疑問符 (?) の代わりにスラッシュ (/) を使用したいと考えています。

これは私のコードです:

マップルート:

routes.MapRoute(
    name: "Organisation",
    url: "{controller}/{action}/{startindex}/{begin}/{end}/{type}",
    defaults: new { controller = "Organisation", action = "getOrganisations" }
);

アクションリンク:

@Html.ActionLink("Organisation", "getOrganisations", "Organisation", new { startindex = 0, begin= "a", end= "f", type = "all" }, null)

私が取得するURL:

http://localhost:1566/Organisation/getOrganisations?startindex=0&begin=a&end=f&type=all

欲しいURL:

http://localhost:1566/Organisation/getOrganisations/0/a/f/all

解決

私はそれを行う方法を見つけました。こうやって:

@Html.RouteLink("Org","Organisation",new { startindex = 0, begin= "a", end= "f", type= "all" })

基本的にRouteLink、ルート名とルートパラメータをパラメーターとして受け取る を使用できます:)

編集(ジャスティン用)

  public ActionResult getOrganisations(int startindex, string begin, string end, string type)
    {
        List<'stored procedure'> retList= new List<'stored procedure'>();
        retList= Model.GetOrganisations(startindex, Convert.ToInt32(Request.Cookies["pagesize"].Value), begin, end, type);
        return View(retList);
    }
4

0 に答える 0