5
我想知道是否有可能在ASP.NET MVC中編寫一個控制器操作,並將其作爲XDocument的參數。這當然意味着表單文章會發送一串XML。是否可以將XDocument作爲參數傳遞給ASP.NET MVC中的操作?
有什麼特別的,我需要做,接受這個作爲參數?
我想知道是否有可能在ASP.NET MVC中編寫一個控制器操作,並將其作爲XDocument的參數。這當然意味着表單文章會發送一串XML。是否可以將XDocument作爲參數傳遞給ASP.NET MVC中的操作?
有什麼特別的,我需要做,接受這個作爲參數?
你可以寫一個自定義類型的粘合劑和在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
}
}