I have asp.net mvc 3 application. I have build the EDIT View which consist of different checkbox with same name and different value. I want to checked the checkbox by matching value of checkbox with the value in array of the string of c#.
Action:
public ActionResult Edit(int id)
{
string[] AllRole = roleassign.Role.Split(',');
ViewBag.allrole = AllRole;
ViewBag.role = ivr.get_all_role();
return View();
}
AllRole is array String consist of "administrator","member","supervisor"
View
@foreach (var list in ViewBag.role)
{
<input type="checkbox" name="role" [email protected] /> @list.Name
}
How Can I loop through the ViewBag.allrole array string in jquery and checked the checked box which have value that is in the ViewBag.allrole array string. Edited In View It Creates Entire set of Checkbox of all avaiable Role as follows:
<input type="checkbox" value="Administrator" name="role">
Administrator
<input type="checkbox" value="Moderator" name="role">
Moderator
<input type="checkbox" value="voice" name="role">
voiceanchor
<input type="checkbox" value="member" name="role">
member
If the ViewBag.allrole consist of array of "administrator","moderator" then I want to checked the checkbox with those value in checkbox using jquery