Note that there are some explanatory texts on larger screens.

plurals
  1. POForm field values aren't binding to model
    primarykey
    data
    text
    <p>I've created a simple MVC application that takes information from a form and passes it to a controller</p> <p>View:</p> <pre><code>@model MvcApplication1.Models.BetChargeModel @using (Html.BeginForm()) { &lt;div&gt; @Html.TextBoxFor(m=&gt;m.numerators[0]) / @Html.TextBoxFor(m=&gt;m.denominators[0]) &lt;/div&gt; &lt;div&gt; @Html.TextBoxFor(m =&gt; m.numerators[1]) / @Html.TextBoxFor(m =&gt; m.denominators[1]) &lt;/div&gt; &lt;div&gt; &lt;input type="submit" value="Calculate" /&gt; &lt;/div&gt; } </code></pre> <p>Controller:</p> <pre><code> public ActionResult Index() { BetChargeModel model = new BetChargeModel(); model.numerators = new List&lt;double&gt;(); model.denominators = new List&lt;double&gt;(); model.denominators.Add(1); model.denominators.Add(1); model.numerators.Add(0); model.numerators.Add(0); return View(model); } [HttpPost] public ActionResult Index(BetChargeModel model) { double odds1 = model.numerators[0] / model.denominators[0]; double odds = model.numerators[1] / model.denominators[1]; //other code } </code></pre> <p>Model:</p> <pre><code> public class BetChargeModel { public List&lt;double&gt; numerators { get; set; } public List&lt;double&gt; denominators { get; set; } public double result { get; set; } } </code></pre> <p>When I run this and try and post back information from the View the Model is coming back empty (full of null fields and zeros). Why is the data in my Textbox's not binding to the model?</p> <p>(Edit: I've changed the model properties and reference to Numerators, Denominators and Result but haven't updated those here for sake of brevity)</p>
    singulars
    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.
 

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