Asp.net MVC 3关于URL的帮助 [英] Asp.net MVC 3 help regarding URL
问题描述
我正在使用MVC3制作应用程序,但我有一个类似
的URL
其中uname是用户的用户名值(例如abc123)
http://localhost:5000/UserProfile/ShowProfile/abc123
我想在控制器中检索此值
我如何找回它?
我已经在global.asax.cs中注册了路由,但不知道如何检索它
我的动作是
Hi,
I am making an application with MVC3 i have a URL like
where uname is the value of username of the user (for eg abc123)
http://localhost:5000/UserProfile/ShowProfile/abc123
i want to retrieve this value in controller
how can i retrieve it??
I have registered routing in global.asax.cs but have no idea how to retrieve it
my Action is
public ActionResult ShowProfile(string customuserName)
{
}
推荐答案
根据您的示例,Controller = UserProfile和Action = ShowProfile.现在到了这一点,检查这种url的路由
您的路线应为:
Based on your example the Controller = UserProfile and Action=ShowProfile. Now coming to the point, check the routing for this kind of url
Your route should be:
routes.MapRoute(
"Default",
"{controller}/{action}/{customuserName}",
new { controller = "UserProfile", action = "ShowProfile", customuserName = UrlParameter.Optional }
);
//Then the action will be:
public ActionResult ShowProfile(string customuserName)
{
}
//so, change the parameter name that you defined in routing also.
我想介绍更多有关路由的信息,但这会分散您的注意力.请阅读有关路由的信息,以免发生路由错误.
I would like tell more about routing, but it will be distracting. Please read about the routing so that you can avoid routing mistakes.
这篇关于Asp.net MVC 3关于URL的帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!