0

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.

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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
I follow a lot of the practices that you will find here: codeclimber.net.nz/archive/2009/10/27/… This is a good list of the extensibility points like ModelBinders: codeclimber.net.nz/archive/2009/04/08/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.