2011-05-19 117 views

回答

6

你可以写一个自定义类型的粘合剂和在Global.asax中的应用程序启动事件处理程序进行注册:

protected void Application_Start() 
{ 
    ModelBinders.Binders.Add(typeof(XDocument), new YourXDocumentBinder()); 
} 

的MVC管道将自动调用粘合剂,当它遇到一个参数的XDocument的动作。

粘结剂的实现将是这个样子:

public class YourXDocumentBinder : DefaultModelBinder 
{ 
    public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) 
    { 
     // handle the posted data 
    } 
} 
相关问题