I have such model
public class TutorialModel
{
public string TitleWord { get; set; }
public List<string> PossibleAnswers { get; set; }
public List<bool> Colors { get; set; }
}
and Controller
public class TutorialController : Controller
{
//
// GET: /Tutorial/
private TutorialModel model = new TutorialModel();
public ActionResult Index(TutorialModel paramModel)
{
model.TitleWord = "Go";
model.Colors = new List<bool>();
model.PossibleAnswers = new List<string>();
model.PossibleAnswers.Add("1");
model.PossibleAnswers.Add("2");
model.PossibleAnswers.Add("3");
model.PossibleAnswers.Add("4");
return View(this.model);
}
public ActionResult PressButton(int? id)
{
if (model.TitleWord == model.PossibleAnswers[(int) id])
{
model.Colors[(int) id] = true;
}
return RedirectToAction("Index", model);
}
}
with view
@{
ViewBag.Title = "Tutorial";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<button type="button" class="btn btn-default">@Model.TitleWord</button>
<br/>
@{
var textColor = "green";
}
<div class="btn-group">
@for (int i = 0; i < Model.PossibleAnswers.Count; i++)
{
<button type="button" class="btn btn-default" style="color: @textColor" onclick = " window.location.href = '@Url.Action("PressButton", "Tutorial", new {id = i})' ">@Model.PossibleAnswers[i]</button>
}
</div>
And after I press one of the buttons I need to get my model which I use in view and button which I pressed. Info about button I got, but I have no idea how to get info sent model from view to controller. Please, help me with this problem.