0

このルートマップを定義しました。

  routes.MapRoute("default", // route name
            "{controller}/{action}/{id}", // url with parameters
            new { controller = "home", action = "index", id = UrlParameter.Optional }, // parameter defaults
            new string[] { "mobilesurveys.mt.controllers" }
        );

これは完全に機能します。別のルートマップを追加したい

   routes.MapRoute("couponreedem", // route name
            "{controller}/{action}/{clientname}", // url with parameters
            new { controller = "Rc", action = "index", id = UrlParameter.Optional }, // parameter defaults
            new string[] { "mobilesurveys.mt.controllers" }
        );

私はこのように定義しました。ここでRcは私のコントローラーです。そして私は.com/Rc / Rc/sammyとしてURLを与えています

およびコントローラーのメソッドは次のように定義されます

  public ActionResult Rc(string clientname)
    {

        viewModel =dataRc.ProductCategoryGet();
        return View(viewModel);
    }

clientnameは常にnullになります。既存のルートが邪魔されないように別のルートを追加する方法。

ありがとう。

4

1 に答える 1

1

実際には同じように見えます。ただし、新しいものが必要な場合は、このようなものを試すことができ、デフォルトのものより上にある必要があります。

 routes.MapRoute("couponreedem", // route name
            "RC/{action}/{clientname}", // url with parameters
            new { controller = "Rc", action = "index", clientname = UrlParameter.Optional }, // parameter defaults
            new string[] { "mobilesurveys.mt.controllers" }
        );

これでRC/でルートが修正されます...また、アクションにはIndexという名前を付ける必要があります

  public ActionResult Index (string clientname)
    {

        viewModel =dataRc.ProductCategoryGet();
        return View(viewModel);
    }
于 2012-06-13T15:29:34.937 に答える