Note that there are some explanatory texts on larger screens.

plurals
  1. POBind Checkbox value to an Object
    primarykey
    data
    text
    <p>This is the code in my view <code>&lt;% using (Html.BeginForm("Add", "Objectives", FormMethod.Post, new { id = "formElem", name = "formElem" })) { %&gt; </code></p> <pre><code> &lt;table&gt; &lt;tr&gt; &lt;th&gt;Investment Objective&lt;/th&gt; &lt;th&gt;Rank1&lt;/th&gt; &lt;th&gt;Rank2&lt;/th&gt; &lt;th&gt;Rank3&lt;/th&gt; &lt;th&gt;Rank4&lt;/th&gt; &lt;th&gt;Rank5&lt;/th&gt; &lt;th&gt;Rank6&lt;/th&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Conservation of Capital&lt;/td&gt; &lt;td&gt;&lt;%=Html.CheckBox("ConservationofCapitalRank", false, new {value=1} )%&gt;&lt;/td&gt; &lt;td&gt;&lt;%=Html.CheckBox("ConservationofCapitalRank", false, new {value=2} )%&gt;&lt;/td&gt; &lt;td&gt;&lt;%=Html.CheckBox("ConservationofCapitalRank", false, new {value=3} )%&gt;&lt;/td&gt; &lt;td&gt;&lt;%=Html.CheckBox("ConservationofCapitalRank", false, new {value=4} )%&gt;&lt;/td&gt; &lt;td&gt;&lt;%=Html.CheckBox("ConservationofCapitalRank", false, new {value=5} )%&gt;&lt;/td&gt; &lt;td&gt;&lt;%=Html.CheckBox("ConservationofCapitalRank", false, new {value=6} )%&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Income&lt;/td&gt; &lt;td&gt;&lt;%=Html.CheckBox("IncomeRank", false, new {value=1} )%&gt;&lt;/td&gt; &lt;td&gt;&lt;%=Html.CheckBox("IncomeRank", false, new {value=2} )%&gt;&lt;/td&gt; &lt;td&gt;&lt;%=Html.CheckBox("IncomeRank", false, new {value=3} )%&gt;&lt;/td&gt; &lt;td&gt;&lt;%=Html.CheckBox("IncomeRank", false, new {value=4} )%&gt;&lt;/td&gt; &lt;td&gt;&lt;%=Html.CheckBox("IncomeRank", false, new {value=5} )%&gt;&lt;/td&gt; &lt;td&gt;&lt;%=Html.CheckBox("IncomeRank", false, new {value=6} )%&gt;&lt;/td&gt; &lt;/tr&gt; </code></pre> <p></p> <p> </p> <pre><code> &lt;% } %&gt; </code></pre> <p>I am trying to get the values in an object in in my controller action.</p> <pre><code>[HttpPost] public ActionResult Add(Objectives pObjectives) { return RedirectToAction("Index"); } </code></pre> <p>This is how my Objectives Class looks.</p> <pre><code>public class Objectives { public long ConservationofCapitalRank { get; set; } public long IncomeRank { get; set; } } </code></pre> <p>I am allowing the user to select only one rank at any given time. Now my problem is if i select the checkbox with value 1 the values appear to bind with my object. But if i select the checkbox with value 2 it does not bind.</p> <p>Any suggestion as to why this behavior?</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.
    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