Note that there are some explanatory texts on larger screens.

plurals
  1. POWeird TextBoxFor mapping issue on Edit
    primarykey
    data
    text
    <p>When I'm editting an <code>Animal</code> item, I'm seeing that the field for "ID" is populated with the value of the field "idAnimal". The animal model is retrieved from database (using EF) by the id passed as parameter. The parameter named "id" is the key named "idAnimal" in database.</p> <p>Debugging in the controller, the model has its values OK (ID = null, idAnimal = some int)... and debugging at the Razor view, I can see that using <code>@Model.ID</code> is null also... but once the view is rendered I see a value in the textbox. </p> <p>My model is as follows:</p> <pre><code>public class Animal { public int idAnimal {get; set;} //this is the id in database public int ID {get; set;} //this is the id given at birth to the animal, a business concept //The rest of the properties } </code></pre> <p>In my controller's EDIT action, I have:</p> <pre><code>public virtual ActionResult Edit(int id) { Animal myA = db.Animals.Find(id); return PartialView(myA) } </code></pre> <p>In the view I have:</p> <pre><code>@model MyApp.Model.Animal .... @Html.LabelForX(model =&gt; model.ID) &lt;div class="input"&gt; @Html.TextBoxFor(model =&gt; model.ID, new { @class = "medium", size = 30 }) @Html.ValidationMessageFor(model =&gt; model.ID) &lt;/div&gt; .... </code></pre> <p>The only thing that could be happening, being weird, is that the parameter named "id" (which holds the value in the field "idAnimal") could be interfering some how.</p> <p>Hope this all soup of id's is understandable :)</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.
 

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