0

I am using view bag to get skills. How to get data from viewbag in @html.Checkboxfor().

  ViewBag.ListSkill = GetSkills();


  public List<UserViewModel> GetSkills()
    {
        var client = new RestClient(url);
        var request = new RestRequest("api/Users/GetAllSkillList", Method.GET);
        var response = client.Execute<List<UserViewModel>>(request);


        return response.Data;
    }

I saw many examples using viewbag but they all using but I need to write the code in @html.Checkbox. Please Help.

Ghost
  • 213
  • 1
  • 2
  • 10

1 Answers1

1

You can do the following, but it sounds it would be better to you if you bind the checkbox to a model.

@Html.CheckBox("yourCheckBox", (bool)ViewBag.yourCheckBoxInfo)

Here you have an example: MVC Binding to checkbox

NicoRiff
  • 4,803
  • 3
  • 25
  • 54