我使用了在 Global.asax 文件中配置的自定义模型绑定器。是否可以仅在应用程序的某些区域下使用此模型绑定器?
public class CreatorModelBinder : IModelBinder
{
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
//what logic can i put here so that this only happens when the controller is in certain area- and when it's not in that area- then the default model binding would work
var service = new MyService();
if (System.Web.HttpContext.Current != null && service.IsLoggedIn)
return service.Creator;
return new Creator {};
}
}