Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
248 views
in Technique[技术] by (71.8m points)

html - How does a multiple select list work with model binding in ASP.NET MVC?

If you have a select list set to multiple in ASP.NET MVC, how does the modelbinding work?

What does it return for your selected items, an array?

<SELECT NAME="toppings" MULTIPLE SIZE=5>
    <option value="mushrooms">mushrooms</option>
    <option value="greenpeppers">green peppers</option>
    <option value="onions">onions</option>
    <option value="tomatoes">tomatoes</option>
    <option value="olives">olives</option>
</SELECT>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Yes, by default a multiselectlist will post through an array of the selected values.

This article has further information, including how to use strongly-typed views with a multiselectlist.

From the linked "article":

  • Your model or view model class needs a collection property for the IDs for the selected option items, e.g. List<int> ToppingIds.
  • In the controller action method to which the form containing your multi-select-list POSTs, you can access the selected option items thru the collection property you added to the model or view model class.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...