viewmodel - mvc : convert view model code to viewbag or viewdata -
i sending table data mvc web page through using viewmodel....my code below..now given task send through viewbag or viewdata. passionate programer plz edit code send throgh viewbag or viedata , give basic overview how use them i.e viewmodel or viebag difrntly. thanx in advance.
@{ viewbag.title = "index"; } <h2>index</h2> <div> <br /><br /> <table style="width: 100%;"> <tr> <th>userid</th> <th>username</th> <th>adress</th> </tr> @foreach(var item in viewdata.model) { <tr> <td>@item.userid</td> <td>@item.username</td> <td>@item.adress</td> </tr> } </table> </div> public class detailcontroller : controller { public actionresult index() { viewdata.model = detailmodels.getdata(); return view(); } } public class detailmodels { public static list<user> getdata() { employeeentities context = new employeeentities(); list<user> dt = context.users.asenumerable().tolist(); return dt; } }
just include library above
@using projectname.models
@foreach (users u in model) { <td>@u.userid</td> <td>@u.username</td> <td>@u.adress</td> }
Comments
Post a Comment