views:

59

answers:

1

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.

+2  A: 

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.

Keith Rousseau
Thank you... I had not heard of those before. Argh. I've ben through a number of the asp.net/mvc tutorials but still... Are there any good resources or best practice links around? Matt
Matt W
I follow a lot of the practices that you will find here:http://codeclimber.net.nz/archive/2009/10/27/12-asp.net-mvc-best-practices.aspxThis is a good list of the extensibility points like ModelBinders:http://codeclimber.net.nz/archive/2009/04/08/13-asp.net-mvc-extensibility-points-you-have-to-know.aspx
Keith Rousseau