dropdownlistfor example of binding using ViewData

Source: Internet
Author: User

Pay special attention to the following practices:

The name of the ViewBag for this method must be the same as the name of the last parameter in New SelectList (), which is the default value for the drop-down box, such as:

Viewbag.title = WebConst.UnSelect.Union (New SelectList (WebConst.Dictionary.Where (p = = P.category = "Title"). (p = = p.sort), "Value", "Display", item. Title));

The title of Viewbag.title must and

New SelectList (WebConst.Dictionary.Where (p = = P.category = "Title"). (p = = p.sort), "Value", "Display", item. Title)

The item in the. Title title has the same name, and must also be in the foreground

@Html. dropdownlistfor (p = p.title, viewbag.title as SelectList, new {@class = "Selop"}) p. Title is the same,

Otherwise, errors may occur and require special attention.

Public readonly static Ilist<selectlistitem> unselect = new list<selectlistitem>
{
New selectlistitem{text= "Please select", value= ""},
};

Public readonly static ilist<selectlistitem> YesNo = new list<selectlistitem>
{
New SelectListItem {Text = "no", Value = "false"},
New SelectListItem {Text = "yes", Value = "true"},
};

viewbag.purchaselimited = WebConst.UnSelect.Union (new SelectList (Webconst.yesno, "Value", "Text", item.) purchaselimited));


Viewbag.acceptpromotioninfo = WebConst.UnSelect.Union (new SelectList (Webconst.yesno, "Value", "Text", item.) Acceptpromotioninfo));

Viewbag.title = WebConst.UnSelect.Union (New SelectList (WebConst.Dictionary.Where (p = = P.category = "Title"). (p = = p.sort), "Value", "Display", item. Title));


Viewbag.agerange = WebConst.UnSelect.Union (New SelectList (WebConst.Dictionary.Where (p = = P.category = "Agerange") . (p = = p.sort), "Value", "Display", item. Agerange));

Front desk Use

<li>
<label class= "required" for= "title" > Appellation </label>
<div class= "Selectarea selectArea2 mln5" >
<span class= "SelectedItem" > Selection </span>
@Html. dropdownlistfor (p = p.title, viewbag.title as SelectList, new {@class = "selop"})
<em></em>
</div>
</li>
<li>
<label> Marriage No </label>
<div class= "Selectarea selectArea2 mln5" >
<span class= "SelectedItem" > Selection </span>
@Html. dropdownlistfor (p = p.maritalstatus, viewbag.maritalstatus as SelectList, new {@class = "selop"})
<em></em>
</div>
</li>

dropdownlistfor example of binding using ViewData

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.