Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The problem has been solved!</p> <p><strong>Summary:</strong> After a day of problems and research for the solution it turned out to be something extreamly simple. Since we are creating entries to the sql database, we expose properties of a model to the view that we expect to be used by the user. </p> <p>We were getting a single error causing the ModelState.IsValid to be false. The error was always the same, "[PrimaryKeyId] field is required". </p> <p><strong>Solution:</strong> In our views (.cshtml) we were exposing the primary key property but marking it as hidden. Apparently when you do this, the validation/checking of the model that EF does must check saying, to the effect, if the property is exposed in the view mark it as required and since it is never updated due to it being hidden it gets the default int value on 0, which is not valid as an identifier.</p> <p><strong>This is what the code was</strong></p> <pre><code>&lt;div class="bg-white content-inner"&gt; @Html.HiddenFor(model =&gt; model.PrimaryKeyId)//BAD DO NOT DO THIS &lt;div class="row-fluid"&gt; &lt;div class="span4"&gt; @Html.LabelFor(model =&gt; model.GroupName) &lt;/div&gt; &lt;div class="span4 offset2"&gt; @Html.TextBoxFor(model =&gt; model.GroupName) @Html.ValidationMessageFor(model =&gt; model.GroupName) &lt;/div&gt; &lt;/div&gt; </code></pre> <p>Now without the property within the model we get this:</p> <p>NO ERRORS AND A VALID MODELSTATE! <img src="https://i.stack.imgur.com/Y3t2a.png" alt="NO ERRORS"></p> <p><img src="https://i.stack.imgur.com/PfcP5.png" alt="VALID MODEL STATE"></p> <p>Given that I am still learning about EF and MVC this turned out to be a tough learning experience, but definatly a mistake I won't make again. Hope this can help! </p> <p>Thanks to all gave me advice and helped.</p>
    singulars
    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.
 

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