[英]asp.net mvc ModelBinder always null
i've model binder in my asp.net mvc 4 site. 我在我的asp.net mvc 4网站中建立了模型绑定器。
public class OptionModelBinder : System.Web.Mvc.IModelBinder
{
private const string SessionKey = "Opt";
public object BindModel(ControllerContext controllercontext, System.Web.Mvc.ModelBindingContext bindingContext)
{
Option opt = (Option)controllercontext.HttpContext.Session[SessionKey];
if (opt == null)
{
opt = new Option ();
controllercontext.HttpContext.Session[SessionKey] = opt ;
}
return opt;
}
}
And Controller: 和控制器:
publick ActionResult Index(Option currentOption)
{
//currentOption always null
}
I'm sure it worked before. 我敢肯定它曾经工作过。 Something happened because of the recent updates Solution.
由于最近的更新解决方案,发生了一些事情。 I do not understand what is wrong.
我不明白怎么了。 Please help.
请帮忙。
Check Application_Start method in Global.asax.cs Make sure that there is that something like a 检查Global.asax.cs中的 Application_Start方法确保有类似
ModelBinders.Binders.Add (typeof (Option), new OptionModelBinder ());
it is necessarily 这一定是
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.