开发者

Best way to retrieve XML data in MVC?

开发者 https://www.devze.com 2022-12-18 15:40 出处:网络
If I am passing an XElement or XDocument to my ASP.NET MVC view, what\'s the best (read: easiest) way to repopulate my XML with the values returned from the edit form开发者_开发技巧 on submit?

If I am passing an XElement or XDocument to my ASP.NET MVC view, what's the best (read: easiest) way to repopulate my XML with the values returned from the edit form开发者_开发技巧 on submit?

Thanks,

Matt.


Typically you want a strongly typed model coming into an action, but if you have a good reason to take in XML, then here is the approach I would take:

Create a custom ModelBinder that will do the work for you. In the ModelBinder you can loop through the form and get everything that was submitted and create your XElement. In the global.asax you can specify that you want to use that ModelBinder whenever you have a type of XElement or XDocument.

0

精彩评论

暂无评论...
验证码 换一张
取 消