This is my view code
@using (Html.BeginForm())
{
@Html.LabelFor(m=>m.GroupID)
@Html.DropDownListFor(m => m.GroupID, Model.GroupList, "Please select", new { id = "ddlgrp" })
if (Model==null)
{
foreach(var permission in Model.Permissions)
{
<label>
@Html.RadioButtonFor(m=>m.perm_id,permission.perm_id)
@permission.perm_levelname
</label>
}
}
else
{
foreach(var permission in Model.Permissions)
{
<label>
@if (Model.perm_id.Equals(ViewBag.selectedperms))
{
@Html.RadioButtonFor(m=>m.perm_id,permission.perm_id,true)
@permission.perm_levelname
}
else
{
@Html.RadioButtonFor(m=>m.perm_id,permission.perm_id)
@permission.perm_levelname
}
</label>
}
}
<input type="submit" value="Submit" />
This is my jquery code
$(document).ready(function () {
$("#ddlgrp").change(function () {
$("#log").ajaxError(function (event, jqxhr, settings, exception) {
alert(exception);
});
var grpselected = $("select option:selected").val();
alert(grpselected);
$.get('@Url.Action("CheckPermissions")',
{ id: grpselected }, function (data) {
});
});
});
This is actionmethod
public ActionResult CheckPermissions(int id)
{
tblperm od = new tblperm();
var selectedperms = (from c in db.tblperm where c.grp_id==id select c.perm_id).SingleOrDefault();
ViewBag.selectedperms = selectedperms;
return View(od);
}
Assume for groupip id 1 there is a permisson with permid 1. So when i select 1 from dropdwon corresponding dropdown with id 1 should be checked. I have tried with above code but its not working. Can anybody suggest me where i am going wrong?
What I have tried:
I want to make radiobutton checked based on the value from database