c# - Passing multiple Collections of data from View to Controller (ASP.NET MVC 5) -
in view have next structure ( control of subject*s each *group):
@using (html.beginform()) { @html.antiforgerytoken() <div class="form-horizontal"> @for (int = 0; < viewbag.allgroups.count; i++) { <h4>@viewbag.allgroups[i].code</h4> <select id="e-@i" multiple="multiple"> @foreach (subject subject in viewbag.allsubjects) { <option value="@subject.name">@subject.name</option> } </select> } <input type="submit" value="generate" class="btn btn-default" /> </div> }
the question how can retreive data (i want receive (1)list of groups , and want (2)list of selected subjects each group in list(1)) in controller?
thank in advance.
recommended way use typed view model object
public class groupviewmodel { public string code { get;set; } public list<subject> allsubjects { get; set; } }
pass list model razor view in controller.
return new view(new list<groupviewmodel>()); // populated one.
use list in view.
@model ilist<groupviewmodel> @for (int = 0; < model.count; i++) { <h4>model[i].code</h4> <select id="e-@i" multiple="multiple"> @foreach (subject subject in model[i].allsubjects) { <option value="@subject.name">@subject.name</option> } </select> }
Comments
Post a Comment