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