c# - Access Generics List in ASP.NET MVC 5 View -


i getting started mvc , have following model

public class formcontrols {      //properties of formcontrols object     public string formcname { get; set; }     public string formctype { get; set; }     public string formccss { get; set; }     public string formcenabled { get; set; }     public string formcdefaultval { get; set; }  } 

i created following control , querying database using linq select records. each record have added list.

    public actionresult index()     {          var datacontext = new editprofileformfieldsdatacontext();         var controls = c in datacontext.controls                        select c;          list<formcontrols> fields = new list<formcontrols>();          foreach(var fc in controls)         {               //create object generic list             formcontrols epc = new formcontrols();             epc.formcname = fc.control_name;             epc.formctype = fc.control_type;             epc.formccss = fc.control_css;             epc.formcenabled = fc.control_enabled;             epc.formcdefaultval = fc.control_defaultval;              //add object formcontrols generic list             fields.add(epc);         }            return view("editprofile");     } 

my question how access list using razor in view? trying loop through list created in view. new mvc , think on thinking lot of :) thanks!

you can make model of view list. put @ top of view:

@model list<formcontrols> 

change return of index() method:

return view("editprofile", fields); 

then can access view using @model. example, iterate through it:

@foreach (var field in model) {     <p>@field.formcname</p> } 

Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -