Html.dropdownlis Binding Database

Source: Internet
Author: User

Effect:

Method One:

View:

1 <Divclass= "Col-md-md-4">2                  <Divclass= "Input-group">3                    <spanclass= "Input-group-addon">Department:</span>                  4 @Html. DropDownList ("F_groupid", viewdata["Consumergroup"] as SelectList, "Please select", new {@class = "fo Rm-control "})5                 </Div>6 </Div>

Note:"F_groupid" is equivalentto Name= "F_groupid", I use the Kendoui grid, so name="F_groupid" is bound Kendo schema f_ GroupID

Controller:

                list<acc_group> AG = SDT. Acc_group.tolist ();                 Select New " F_groupid " " F_groupname " );                viewdata["consumergroup"select;

Entity:

1   Public Partial classAcc_group2     {3          Public intF_groupid {Get;Set; }4          Public stringF_groupname {Get;Set; }5          Public intF_groupno {Get;Set; }6          Public intF_parentid {Get;Set; }7}

Method Two:

View:

1  @Html. DropDownList ("database", NULL, "Please select", new {@class = "Form-control"})

Controller:

List<acc_group> AG =SDT.                Acc_group.tolist (); varSelectitemlist =NewList<selectlistitem>(); {                    NewSelectListItem () {Value ="0", Text ="Select Department", Selected =true };                }; varSelectList =NewSelectList (AG,"F_groupid","F_groupname");                Selectitemlist.addrange (SelectList); Viewbag.database= Selectitemlist;

Html.dropdownlis Binding Database

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.