Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get data from view to controller mvc4?
    primarykey
    data
    text
    <p>I have such model</p> <pre><code> public class TutorialModel { public string TitleWord { get; set; } public List&lt;string&gt; PossibleAnswers { get; set; } public List&lt;bool&gt; Colors { get; set; } } </code></pre> <p>and Controller </p> <pre><code>public class TutorialController : Controller { // // GET: /Tutorial/ private TutorialModel model = new TutorialModel(); public ActionResult Index(TutorialModel paramModel) { model.TitleWord = "Go"; model.Colors = new List&lt;bool&gt;(); model.PossibleAnswers = new List&lt;string&gt;(); 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); } } </code></pre> <p>with view</p> <pre><code>@{ ViewBag.Title = "Tutorial"; Layout = "~/Views/Shared/_Layout.cshtml"; } &lt;button type="button" class="btn btn-default"&gt;@Model.TitleWord&lt;/button&gt; &lt;br/&gt; @{ var textColor = "green"; } &lt;div class="btn-group"&gt; @for (int i = 0; i &lt; Model.PossibleAnswers.Count; i++) { &lt;button type="button" class="btn btn-default" style="color: @textColor" onclick = " window.location.href = '@Url.Action("PressButton", "Tutorial", new {id = i})' "&gt;@Model.PossibleAnswers[i]&lt;/button&gt; } &lt;/div&gt; </code></pre> <p>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.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload