Checked the information for a morning, found a more effective method
Background controller: Publicactionresult Index ()
{
list<string> colors = new list<string> ();
Colors. ADD ("Red");
Colors. ADD ("green");
Colors. ADD ("Blue");
viewdata["listcolors"] = colors;
return View ();
}
Front Desk Interface:
@foreach (var color in viewdata["Listcolors"] as List<string>)
{
@color
}
I think this is relatively clear and simple.
There are several other ways of transmitting values (data transfer between view and action)
ViewBag Dynamic Type
Background controller: Publicactionresult Index ()
{
dictionary<string, string> stackholder = new dictionary<string, string> (); Stackholder. ADD ("Client", "Mr. client"); Stackholder. ADD ("Manager", "Mr. Joy"); Stackholder. ADD ("Team Leader", "Mr.toy"); Stackholder. ADD ("Sr. Developer", "Mr.dojoy"); Stackholder. ADD ("Developer", "Mr Nodoy"); Viewbag.stackholder = Stackholder;
return View ();
}
Front Desk Interface:
@ Viewbag.stackholder
ViewData Weakly-State
Model Dynamic Type
Backstage: Return View (data)//equivalent to deposit Viewdata.model
Front Desk: Model
MVC foreground gets the values in an array of ViewData