How to bind enumeration values in the mvc drop-down box and the mvc drop-down box to Enumeration

Source: Internet
Author: User

How to bind enumeration values in the mvc drop-down box and the mvc drop-down box to Enumeration

In general BS program development, I am used to using the asp.net control to directly bind data to the background. However, I recently encountered a problem. In mvc, how can I bind background data to the foreground?

Previously, we listed data directly on the front-end page as follows:

<SOA: HBDropDownList ID = "ddlReadState" runat = "server" Width = "200px"> <asp: listItem Text = "select" Value = "-1"> </asp: ListItem> <asp: ListItem Text = "completed" Value = "1"> </asp: listItem> <asp: ListItem Text = "unfinished, known" Value = "0"> </asp: ListItem> </SOA: HBDropDownList>
Alternatively, bind the data source directly in the background using the drop-down box Control ID.

this.ddlReadState.DataSource = List<State>;
However, in mvc, the controller cannot directly use the control ID to bind data. It can only bind data at the front-end. How can we update data?

Model Code:

Public class SignQuoteFormViewModel: WfDataViewModelBase <SignQuoteForm> {public string ReadState {get; set;} public string ReadRemark {get; set;} public List <SelectListItem> GetSelectList () {List <SelectListItem> list = new List <SelectListItem> {new SelectListItem {Text = "select", Value = "-1 "}, new SelectListItem {Text = "completed", Value = "0"}, new SelectListItem {Text = "unfinished, please know", Value = "1 "}}; return list; }} public enum selectListStatus {// <summary> // completed /// </summary> [EnumItemDescription ("completed")] NoFinish = 0, /// <summary> /// incomplete /// </summary> [EnumItemDescription ("incomplete")] Finished = 1}
Front-end data binding:

<div style="padding:15px;border-radius:0;" class="panel-body">                @Html.ViewComponent().DropDownList(Html, m => m.ReadState, Model.GetSelectList(), new { @class = "form-control" })            </div>
As follows:






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.