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
}
}