ASP.NET MVC: Binding a Complex Type to a Select

前端 未结 3 1525
北恋
北恋 2020-12-28 16:30

I am trying to work out if there is built-in support for binding complex types to form elements.

To use a common hypothetical situation: I have a Product entity that

相关标签:
3条回答
  • 2020-12-28 17:11

    The closest I think that it will come is overriding the ToString() method in the class to output meaningful information to the DropDownList - but not much else.

    You may be able to bind the IEnumerable collection to a DropDownList and then retrieving its SelectedItem when the form is submitted - that is the cheapest way I can think of.

    0 讨论(0)
  • 2020-12-28 17:15

    Please check this, as I think that talks about your question, it seems that the S#arp guys have solved it and it's easily "rip"'able if you don't use their stuff.

    Anyway I think it's somewhat dangerous to automatically load entities from whatever the user posts... will have to think about it.

    0 讨论(0)
  • 2020-12-28 17:25

    I haven't yet tried the DefaultModelBinder for complex types, but you could always use MvcContrib's CastleBind (borrowed from the Castle Project) which gives you complex type binding easily, including arrays.

    See http://blogger.forgottenskies.com/?p=258

    0 讨论(0)
提交回复
热议问题