lundi 17 août 2015

post back the checkbox value in MVC

I have a model as 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 which flag will be 1 if the user has access to that menu else 0

I am able to show this in a view using pagedlist

@foreach (var item in Model)
<tr class="">
@if (item.flag == 1)
<input type="checkbox" name="flags[]" checked="checked" id="" value="1" />
<input type="checkbox" name="flags[]"  id="" value="0" /> 
<td>@Html.DisplayFor(modelItem => item.module) </td>
<td> @Html.DisplayFor(modelItem => item.submenu)</td>

it will give the below output


Here user has access to 5 menus and no access to 1 Now the admin can change the privileges by checking and un-checking the checkboxes.

My post actionresult signature is as below

 public ActionResult security(client_module_security c1,string[] flags)


but this is not posting back the values here and the flag string contain only checked numbers. screen shot below

module flags

Please correct me if my logic is bad. What changes to be done in-order to update the same?

Aucun commentaire:

Enregistrer un commentaire