Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.MVC 2 RTM + ModelState Error at Id property
    primarykey
    data
    text
    <p>I have this classes:</p> <pre class="lang-c# prettyprint-override"><code>public class GroupMetadata { [HiddenInput(DisplayValue = false)] public int Id { get; set; } [Required] public string Name { get; set; } } [MetadataType(typeof(GrupoMetadata))] public partial class Group { public virtual int Id { get; set; } public virtual string Name { get; set; } } </code></pre> <p>And this action:</p> <pre class="lang-c# prettyprint-override"><code>[HttpPost] public ActionResult Edit(Group group) { if (ModelState.IsValid) { // Logic to save return RedirectToAction("Index"); } return View(group); } </code></pre> <p>That's my view:</p> <pre class="lang-c# prettyprint-override"><code>&lt;%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage&lt;Group&gt;" %&gt; &lt;asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"&gt; &lt;% using (Html.BeginForm()) {%&gt; &lt;fieldset&gt; &lt;%= Html.EditorForModel() %&gt; &lt;p&gt; &lt;input type="submit" value="Save" /&gt; &lt;/p&gt; &lt;/fieldset&gt; &lt;% } %&gt; &lt;div&gt; &lt;%=Html.ActionLink("Back", "Index") %&gt; &lt;/div&gt; &lt;/asp:Content&gt; </code></pre> <p>But ModelState is always invalid! As I can see, for MVC validation 0 is invalid, but for me is valid. How can I fix it since, I didn't put any kind of validation in Id property?</p> <p><strong>UPDATE:</strong> I don't know how or why, but renaming Id, in my case to PK, solves this problem.</p> <p>Do you know if this an issue in my logic/configuration or is an bug or expected behavior?</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