Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC3 Html.RadioButton statpost back to controller
    text
    copied!<p>I have the following model in my mvc3 application. I want to have two radio buttons on the view that map to Weight and Quantity (these are bit fields in the database).</p> <pre><code>public Unit() { this.OrderLineQuantity = new HashSet&lt;OrderLine&gt;(); this.OrderLineWeight = new HashSet&lt;OrderLine&gt;(); } public int ID { get; set; } public System.Guid UserId { get; set; } public string ShortDescription { get; set; } public string Desciption { get; set; } public System.DateTime AddDate { get; set; } public System.DateTime UpdateDate { get; set; } public Nullable&lt;bool&gt; Weight { get; set; } public Nullable&lt;bool&gt; Quantity { get; set; } public virtual ICollection&lt;OrderLine&gt; OrderLineQuantity { get; set; } public virtual ICollection&lt;OrderLine&gt; OrderLineWeight { get; set; } </code></pre> <p>I have the (simplified) following in my strongly typed razor view:</p> <pre><code>@using (Html.BeginForm()) { @Html.ValidationSummary(true) &lt;fieldset&gt; &lt;legend&gt;Unit&lt;/legend&gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt;@Html.LabelFor(model =&gt; model.Weight)&lt;/td&gt; &lt;td&gt;@Html.LabelFor(model =&gt; model.Quantity)&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; @Html.RadioButton("unitType", "false", "Weight") @Html.ValidationMessageFor(model =&gt; model.Weight) &lt;/td&gt; &lt;td&gt; @Html.RadioButton("unitType", "false", "Quantity") @Html.ValidationMessageFor(model =&gt; model.Quantity) &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;p&gt; &lt;input type="submit" value="Create" /&gt; &lt;/p&gt; &lt;/fieldset&gt; </code></pre> <p>}</p> <p>The issue I am having is when I debug the post back to the controller the values for the radio buttons are null. I'm a bit confused as I think I have named the controls correctly in the view. Can someone please help me get the values posting back to the controller correctly. Thanks in advance.</p>
 

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