【发布时间】:2009-08-15 13:45:58
【问题描述】:
我有一个类似这样的网址:
example.com/profile/publicview?profileKey=5
我想用路由把它缩短到这个程度
example.com/profile/5
我该怎么做?
这是我的尝试:
routes.MapRoute(
"Profile", "Profile/{profileKey}",
new { controller = "Profile", action = "PublicView", profileKey ="" }
);
但是他产生了这个错误:
参数字典包含一个 参数“profileKey”的空条目 不可为空的类型'System.Int32' 对于方法 'System.Web.Mvc.ActionResult 公共视图(Int32)'在 'Website.Controllers.ProfileController
动作方法
public ActionResult PublicView(int profileKey)
{
//stuff
}
【问题讨论】:
-
您能否将代码发布到您的 PublicView() 操作方法中引发异常的地方?
-
完成。没有包括方法体,因为它没有那么远。
-
试试我和 Mike 同时给出的答案。
标签: asp.net-mvc url-routing asp.net-mvc-routing