c# - Pass model and modellist data together to a partial view - ASP.NET MVC 5 -
i working on asp.net mvc 5 app. need create form in partial view. in form passing viewmodel
hold related model class instances. 1 of model classes, need pass data list can print in foreach loop in razor code.
now need pass model of few classes , list data of 1 model view...
many thanks
view model:
public class qualificationviewmodel : leo.dal.viewmodels.iqualificationviewmodel { public qualification _qualification { get; set; } public qualificationtype _qualificationtype { get; set; } public subject _subject { get; set; } public componentscheme _componentscheme { get; set; } }
controller:
[httpget] public actionresult createnewqualification() { var model = new qualificationviewmodel(); var componentlist = //imagin list of components need send along viewmodel ?????????????????????? return partialview("partialqualification_create", model); }
view (need fix part (display list data here )
@model leo.dal.viewmodels.qualificationviewmodel @*<div class="_formgrid_block_1"> <table class="table"> <tr> <th> @html.displaynamefor(model => model._componentscheme.componenttitle) </th> <th>head1</th> </tr> @foreach (var item in model._componentscheme) { <tr> <td> @html.displayfor(modelitem => modelitem._componentscheme.componenttitle) </td> <td> aaaaaaaaaaaaaa </td> </tr> } </table> </div>*@
if understand correctly want send viewmodel partial view , in cases send list (componentlist) same view? if want have many ways:
create new view model holds 2 properties: qualificationviewmodel , list of type want send view , bind view new model
public class extendedqualificationviewmodel { public qualificationviewmodel oldviewmodel { get; set; } public ienumerable<sometype> componenetlist {get;set;} }
and in view
@model leo.dal.viewmodels.extendedqualificationviewmodel
or can same extension of original model this:
public class extendedqualificationviewmodel : qualificationviewmodel { public ienumerable<sometype> componenetlist {get;set;} }
and same binding in view.
lastly can add list viewdata , retrieve in view.
Comments
Post a Comment