vendredi 30 janvier 2015

checkboxes matrix with MVC4

I need to disply a matrix of checkboxes like the one in here asp.net mvc checkbox/radiobutton matrix model-binding


well, instead of subquestions I haves roles and types, so here is my code:


my models:



public class role
{
public role()
{
types = new List<role_type>();
}

[Key]
public int role_id { get; set; }
public string role_name { get; set; }
public int role_value { get; set; }
public Boolean IsSelected { get; set; }

public IList<role_type> types { get; set; }
}

public class role_type
{
public int Id { get; set; }
public Boolean IsSelected { get; set; }
public string type { get; set; }
}


My view Model:



public class roleViewModel
{
public roleViewModel()
{
Roles = new List<role>();
}
public int ID { get; set; }

public IList<role> Roles { get; set; }
}


My controller:



public class roleviewmodelController : Controller
{
private Context db = new Context();

[HttpGet]
public ActionResult Index(roleViewModel rvm)
{
return View(rvm);
}
}


and my view



@model UsersManagement.Models.roleViewModel
@{
ViewBag.Title = "Index";
}


@for (var i = 0; i < Model.Roles.Count(); i++)
{
<div id="roles">
<ul>
@for (var j = 0; j <4; j++)
{
<li>@Html.CheckBoxFor(m=>Model.Roles[i].types[j].IsSelected)</li>
}
</ul>
</div>
}


this doesn't display anything, what am i missing?


the types should be like (Edit, Delete, Read, Create) and the roles like: manage companies, manage invoices, etc...


PS: My final goal is to customise the authorization system but this is another issue.





Aucun commentaire:

Enregistrer un commentaire