2011-05-19 119 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 
    } 
} 
相關問題