ASP.net MVC routing with optional first parameter

前端 未结 4 1551
南笙
南笙 2020-12-08 23:32

I need to provide following functionality for one of the web sites.

http://www.example.com/[sponsor]/{controller}/{action}

Depending on the

4条回答
  •  时光取名叫无心
    2020-12-09 00:11

    i will show you in simple example you don't have to change in Route.config.cs only you have to do in Route.config.cs just put in

    Optional URI Parameters First and Default Values

    Route.config.cs

    routes.MapMvcAttributeRoutes();
    

    Controller

    [Route("{Name}/Controller/ActionName")]
            public ActionResult Details(string Name)
            {            
    
                  // some code here 
    
                return View();
            }
    

    Results

    localhost:2345/Name/controllername/actionname/id(optional)

提交回复
热议问题