0
我建设使用默认的URL路径 «/ {控制器}/{行动}/{ID}».NET MVC自定义类型
我的问题一个asp.net MVC应用程序与此路线中的最后一项,即身份证号。 mvc框架会自动将任何内容放入id中,以便在操作中声明的参数的类型。
例如:
网址:/ myController的/ myaction/1
公共类myController的:控制器 {
public ActionResult myaction(int id)
{
// it works id == 1
}
}
但是,如果我在动作声明一个参数自定义类型的mvc框架无法将路由的最后部分映射到参数。
例如:
网址:/ myController的/ myaction/xpto
公共类myController的:控制器 {
public ActionResult myaction(MyType id)
{
// it fails to cast "xpto" to my type
}
}
哪里应在框架挖掘教它如何做到这一点?
太棒了!而已! 我认为Model Binder只适用于Forms。 – Gnomo 2009-09-24 13:28:56