asp.net mvc - post back the checkbox value in MVC -
i have model below
public class security { public long id { get; set; } public long user_id { get; set; } public long submenu_id { get; set; } public long module_id { get; set; } public long flag { get; set; } public string module { get; set; } public string submenu { get; set; } }
in flag
1
if user has access menu else 0
i able show in view using pagedlist
@foreach (var item in model) { <tr class=""> <td> @if (item.flag == 1) { <input type="checkbox" name="flags[]" checked="checked" id="@item.id" value="1" /> } else { <input type="checkbox" name="flags[]" id="@item.id" value="0" /> } </td> <td>@html.displayfor(modelitem => item.module) </td> <td> @html.displayfor(modelitem => item.submenu)</td> </tr> }
it give below output
here user has access 5
menus , no access 1
admin can change privileges checking , un-checking checkboxes.
my post actionresult signature below
public actionresult security(client_module_security c1,string[] flags) { }
but not posting values here , flag string contain checked numbers. screen shot below
please correct me if logic bad. changes done in-order update same?
model:
public class security { public long id { get; set; } public long user_id { get; set; } public long submenu_id { get; set; } public long module_id { get; set; } public bool flag { get; set; } public string module { get; set; } public string submenu { get; set; } }
view:
@for(var = 0; i<model.count; i++) { @html.hiddenfor(m=>m[i].id) <tr class=""> <td> @html.checkboxfor(m=>m[i].flag) </td> <td>@html.displayfor(modelitem => modelitem[i].module) </td> <td> @html.displayfor(modelitem => modelitem[i].submenu)</td> </tr> }
controller
public actionresult security(ilist<security> model) { //each 1 of items in model have id flag property filled data }
Comments
Post a Comment