In asp.net mvc, you can use the Dropdownlistfor method to allow users to select a number in a list that has been set. The usage is not complex, here simply makes a record.
First we want to define a Model, the user selects the specified value in the DropDownList to assign to the attribute Readytimehour
public class Ericsunmodel
{public
string Readytimehour {get; set;}
}
After the model is defined, the logic of the controller is then processed
"Note: Here is a viewdata to record all the list values to be displayed in the DropDownList."
Public ActionResult ericsunaction ()
{
Ericsunmodel Esmodel = new Ericsunmodel ();
Esmodel.readytimehour = ";
" Generatereadytimeviewdata ();
Return View (Esmodel);
}
private void Generatereadytimeviewdata ()
{
viewdata["hourlist"] = Gettimehourlist ();
}
Private list<selectlistitem> gettimehourlist ()
{
list<selectlistitem> hourlist = new List< Selectlistitem> ();
for (int i = 0; i < i++)
{
if (I <)
{
Hourlist.add (new SelectListItem {Text = "0" + i.to String (), Value = "0" + i.tostring ()});
else
{
Hourlist.add (new SelectListItem {Text = i.ToString (), Value = i.ToString ()});
}
return hourlist;
}
Next we can use the following line of code in the View to bind DropDownList
"NOTE: The first parameter is the property in the binding Model , that is,--> to assign a value to this property"
"NOTE: The second parameter is DropDownList for all data sources"
@Html. Dropdownlistfor (M => m.readytimehour, viewdata["Hourlist"] as list<selectlistitem>)
The screenshot below shows
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/webkf/aspx/