How do I route a URL with a querystring in ASP.NET MVC?

前端 未结 4 1730
有刺的猬
有刺的猬 2020-11-28 15:28

I\'m trying to setup a custom route in MVC to take a URL from another system in the following format:

../ABC/ABC01?Key=123&Group=456

The 01

4条回答
  •  我在风中等你
    2020-11-28 16:25

    You cannot include the query string in the route. Try with a route like this:

    routes.MapRoute("OpenCase", "ABC/ABC{stepNo}",
       new { controller = "ABC1", action = "OpenCase" });
    

    Then, on your controller add a method like this:

    public class ABC1 : Controller
    {
        public ActionResult OpenCase(string stepno, string key, string group)
        {
            // do stuff here
            return View();
        }        
    }
    

    ASP.NET MVC will automatically map the query string parameters to the parameters in the method in the controller.

提交回复
热议问题