ASP.Net MVC Route to Username

后端 未结 5 1173
难免孤独
难免孤独 2020-12-22 17:39

I am trying to create a route with a Username...

So the URL would be mydomain.com/abrudtkhul (abrudtkhul being the username)

My application will have public

5条回答
  •  时光说笑
    2020-12-22 18:28

    routes.MapRoute(
                 "Users",
                  "{username}", 
                  new { controller = "Users", action="ShowUser", username=""});
    

    Ok, what this will do is default the username parameter to the value of {username}

    so even though you've written username="" it'll know to pass the value of {username} .. by virtue of the strings match.

    This would expect

    for the url form

    http://website.com/username

    • Users Contoller
    • ShowUser Action (method in controller)
    • username parameter on the ShowUser action (method)

提交回复
热议问题