asp.net mvc - Get checkbox value placed in partial view table -
i new mvc convept. have 2 model class 1 many relation. find below code.
role:
public partial class approle { public approle() { apppermissions = new hashset<apppermission>(); appusers = new hashset<appuser>(); } public int approleid { get; set; } [required] public string rolename { get; set; } public string roledescription { get; set; } public bool issysadmin { get; set; } public virtual icollection<apppermission> apppermissions { get; set; } public virtual icollection<appuser> appusers { get; set; } }
permission:
public partial class apppermission { public apppermission() { } public int apppermissionid { get; set; } [required] public string name { get; set; } public bool enable { get; set; } [required] [stringlength(50)] public string permissiondescription { get; set; } public guid approleid { get; set; } public approle approle { get; set; } }
apppermission used set access permission different modules. eg: 1. user 2. role 3. products 4. customer
permission created every module using checkbox enable rendered in table.
when rolecreate view rendered, want permission part of view table , rows added during runtime saved database when role saved.
i able rolecreate working , permisions using partial view. however, not able permissions table checkbox data when role saved.
find below rolecreate , parmissionpartialview code.
rolecreate:
@model webopms.models.approle @{ viewbag.title = "create role"; } <script type="text/javascript"> $(document).ready(function () { $(":input[type='submit']").button(); $(":input[type='button']").button(); }) </script> <div class="panel"> @using (html.beginform()) { @html.validationsummary(true) <div class="form-horizontal"> <h3> create role </h3> @html.validationsummary(true, "", new { @class = "text-danger" }) <div class="form-group"> @html.labelfor(m => m.rolename, new { @class = "col-md-2 control-label" }) <div class="col-md-3"> @html.textboxfor(m => m.rolename, new { @class = "form-control" }) @html.validationmessagefor(m => m.rolename, "", new { @class = "text-danger" }) </div> @html.labelfor(m => m.issysadmin, new { @class = "col-md-2 control-label" }) <div class="col-md-1"> @html.checkboxfor(m => m.issysadmin, new { @class = "form-control" }) @html.validationmessagefor(m => m.issysadmin, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @html.labelfor(m => m.roledescription, new { @class = "col-md-2 control-label" }) <div class="col-md-10"> @html.textareafor(m => m.roledescription, new { @class = "form-control" }) @html.validationmessagefor(m => m.roledescription, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> <div class="col-md-offset-2 col-md-10"> <input type="submit" value="create" class="btn btn-default" /> </div> </div> </div> <h4> list of permissions </h4> @*@html.partial("permissionpartialview", model)*@ @html.partial("permissionpartialview", model.apppermissions) } </div> <div> @html.actionlink("go roles", "roleindex", "admin") </div>
permissionpartialview:
@model ienumerable<webopms.models.apppermission> <p> @html.actionlink("create new", "create") </p> <table class="table"> <tr> <th> name </th> <th> enable </th> <th> permissiondescription </th> <th> @html.displaynamefor(model => model.approleid) </th> <th></th> </tr> @foreach (var item in model) { <tr> <td> @html.displayfor(modelitem => item.name) </td> <td> @html.checkboxfor(modelitem => item.enable) </td> <td> @html.displayfor(modelitem => item.permissiondescription) </td> <td> @html.displayfor(modelitem => item.approleid) </td> <td> @html.actionlink("edit", "edit", new { id=item.apppermissionid }) | @html.actionlink("details", "details", new { id=item.apppermissionid }) | @html.actionlink("delete", "delete", new { id=item.apppermissionid }) </td> </tr> } </table>
find below code of rolecreate action in controller:
public actionresult rolecreate() { approle _approle = new approle(); appuser user = database.appusers.where(r => r.username == user.identity.name).firstordefault(); viewbag.list_boolnullyesno = this.list_boolnullyesno(); assembly asm = assembly.getassembly(typeof(webopms.mvcapplication)); var controlleractionlist = asm.gettypes() .where(type => typeof(system.web.mvc.controller).isassignablefrom(type)) .selectmany(type => type.getmethods(bindingflags.instance | bindingflags.declaredonly | bindingflags.public)) .where(m => !m.getcustomattributes(typeof(system.runtime.compilerservices.compilergeneratedattribute), true).any()) .select(x => new { controller = x.declaringtype.name, action = x.name, returntype = x.returntype.name, attributes = string.join(",", x.getcustomattributes().select(a => a.gettype().name.replace("attribute", ""))) }) .orderby(x => x.controller).thenby(x => x.action).tolist(); list<apppermission> perlist = new list<apppermission>(); var list = new list<rolepermissioneditorviewmodel>(); foreach (var st in controlleractionlist) { if ((perlist.any(item => item.name == string.format("{0}-{1}", getsplitstring(st.controller, "controller"), st.action))) == false) { apppermission per = new apppermission(); rolepermissioneditorviewmodel newmdl = new rolepermissioneditorviewmodel(); newmdl.name = string.format("{0}-{1}", getsplitstring(st.controller, "controller"), st.action); newmdl.isenable = true; list.add(newmdl); per.name = string.format("{0}-{1}", getsplitstring(st.controller, "controller"), st.action); per.enable = true; _approle.apppermissions.add(per); perlist.add(per); } } var outobj = list.select(row => new selectlistitem() { text = row.name, value = row.permissionid.tostring(), selected = row.isenable }); viewbag.keydata = outobj; viewdata["pers"] = perlist; return view(_approle); }
i want permission table populate in runtime chebox , when submit pressed both role create , permission screen saved database.
please me can progress in personal project.
regards,
shri
Comments
Post a Comment