comr radiobutton problem asp mvc

0

Good evening, I'm trying to popular varis radiobutton according to the value contained in my database, but I'm not able to do it.

Here is the view with the radiobutton

@model GuialetoLMS.Models.GuialetoModel
@foreach (var choice in Model.Vestibular)
{
    @Html.RadioButton("answer", @choice.idVestibular ) @choice.NomeVestibular
}

And my controller

  public ActionResult PaginaQuestao()
    {
        return View(db.Vestibular.ToList());
    }
    
asked by anonymous 13.01.2018 / 01:49

1 answer

0

Basically your view is expecting a ViewModel GuialetoLMS.Models.GuialetoModel and you are passing one to it a different type, GuialetoLMS.Models.Vestib‌​ular .

If you wanted to just pass the Vestibular list, just change the declaration in your view:

@model GuialetoLMS.Models.Vestib‌​ular
@foreach (var choice in Model)
{
    @Html.RadioButton("answer", @choice.idVestibular ) @choice.NomeVestibular
}

Even if you have included only a small portion of your code, I deduce that the first solution will not solve your problem, since you should want to pass other data that is contained in GuialetoModel , so you should create an instance of that object and popular with the desired content.

public ActionResult PaginaQuestao()
{
    var viewModel = new GuialetoLMS.Models.GuialetoModel();

    //... resto do seu código

    viewModel.Vestibular = db.Vestibular.ToList();

    return View(viewModel);
}
    
13.01.2018 / 13:55