Bre*_*ick 5 asp.net-mvc linq-to-xml
我想知道是否有可能在ASP.NET MVC中编写一个控制器动作,它将XDocument作为参数.这当然只是意味着表单发送一串XML.
有什么特别的东西需要我接受这个作为参数吗?
您可以编写自定义类型绑定器并在global.asax中的Application Start事件处理程序中注册它:
protected void Application_Start()
{
ModelBinders.Binders.Add(typeof(XDocument), new YourXDocumentBinder());
}
Run Code Online (Sandbox Code Playgroud)
当MVC管道遇到带有XDocument参数的操作时,它会自动调用绑定器.
绑定器实现看起来像这样:
public class YourXDocumentBinder : DefaultModelBinder
{
public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
// handle the posted data
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
426 次 |
| 最近记录: |