将 text/xml 读入 ASP.MVC 控制器
如何将文本/xml 读入 ASP.MVC 控制器上的操作?
我有一个 Web 应用程序,它可能会从两个不同的源接收 POSTed Xml,因此 Xml 的内容可能会有所不同。
我希望控制器上的默认操作能够读取 Xml,但是我很难了解如何首先将 Xml 放入操作中。
如果 Xml 一致,我可以使用 Model Binder,但这里不可能。
How do I read text/xml into an action on a ASP.MVC Controller?
I have a web application that may receive POSTed Xml from two different sources so the contents of the Xml may be different.
I want the default action on my controler to be able to read the Xml however I am struggling to see how I can get the Xml into the action in the first place.
If the Xml was consistent I could have used a Model Binder but thats not possible here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以从请求流中读取它:
并且要清理此操作,您可以为 XDocument 编写一个自定义模型绑定器:
您可以在
Application_Start
中注册它:最后:
这显然更干净。
You could read it from the request stream:
and to cleanup this action you could write a custom model binder for a XDocument:
which you would register in
Application_Start
:and finally:
which is obviously cleaner.