Currently I have a custom Model Binder and Model Binder Provider that detects "text/xml", deserializes it using MvcContrib (here is the code/setup), and binds it to a custo开发者_如何学运维m Model that I have, for example:
<User>
<name></name><role></role>
</User>
will bind to a new User()
that has User.name, user.role
(just as you would expect), and the Action of course starts like this:
ActionResult CreateUser(User u) {
Now I am wondering if I can deserialize XML that looks like this:
<Users>
<User><name></name><role></role></User>
<User>...</User>
<User>...</User>
<Users>
And bind it to an Action like this:
ActionResult CreateUsers(List<User> u) {
Try registering your model binder like this:
ModelBinders.Binders.Add(typeof(List<User>), new SimpleUserBinder());
Note: You won't need the ModelBinderProvider because when you specify the List<User>
in your Action it will automatically match the type and call the SimpleUserBinder.
精彩评论