Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
JavaScript
$(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
C#
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
Posted
Updated 4-Feb-16 21:28pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900