title: asp.net mvc scaffolding and GUID as the primary key
body: <p>I have a table with the following structure</p>
  
  <pre><code>GUID uniqueidentifier with default value newid(), and set as primary key
  ID int
  Description varchar(max)
  </code></pre>
  
  <p>I created an Entity Model using visual studio, and generated the views for editing/deleting etc (mvc scaffolding)</p>
  
  <p>The problem is with "Editing", when I click that link, the appropriate form is showed with the correct data, but the "save" button doesn't work at all. Please note that other links (delete,create,details) work perfectly..</p>
  
  <p>So, when I click the "Edit" link, the url is </p>
  
  <p><a href="http://localhost:10871/admin/Edit/e7d0c5ee-7782-411f-920e-7b0d93c924e1" rel="nofollow noreferrer">http://localhost:10871/admin/Edit/e7d0c5ee-7782-411f-920e-7b0d93c924e1</a></p>
  
  <p>and the form is displayed correctly, but the save button doesn't work, no network activity happens. Is something particular about using uniqueidentifers as primary key?</p>
  
  <p>Thanks</p>
  
  <p>---Code---</p>
  
  <p><strong>Edit.cshtml</strong></p>
  
  <pre><code>@using (Html.BeginForm()) {
      @Html.ValidationSummary(true)
      &lt;fieldset&gt;
          &lt;legend&gt;Domain&lt;/legend&gt;
  
          @Html.HiddenFor(model =&gt; model.GUID)
  
          @Html.HiddenFor(model =&gt; model.ID)
  
          &lt;div class="editor-label"&gt;
              @Html.LabelFor(model =&gt; model.Description)
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.EditorFor(model =&gt; model.Description)
              @Html.ValidationMessageFor(model =&gt; model.Description)
          &lt;/div&gt;
  
          &lt;p&gt;
              &lt;input type="submit" value="Save" /&gt;
          &lt;/p&gt;
      &lt;/fieldset&gt;
  }
  
  &lt;div&gt;
      @Html.ActionLink("Back to List", "Index")
  &lt;/div&gt;
  </code></pre>
  
  <p>--AdminController.cs--</p>
  
  <p>// GET: /Admin/Edit/5</p>
  
  <pre><code>public ActionResult Edit(Guid id)
  {
      Domain domain = db.Domains.Single(d =&gt; d.GUID == id);
      return View(domain);
  }
  
  //
  // POST: /Admin/Edit/5
  
  [HttpPost]
  public ActionResult Edit(Domain domain)
  {
      if (ModelState.IsValid)
      {
          db.Domains.Attach(domain);
          db.ObjectStateManager.ChangeObjectState(domain, EntityState.Modified);
          db.SaveChanges();
          return RedirectToAction("Index");
      }
      return View(domain);
  }
  </code></pre>
  
  <p><strong>Edit2</strong>
  In response to a comment by  ZippyV, I added the following code in Edit.cshtml</p>
  
  <pre><code>&lt;div class="editor-label"&gt;
              @Html.LabelFor(model =&gt; model.ID)
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.EditorFor(model =&gt; model.ID)
              @Html.ValidationMessageFor(model =&gt; model.ID)
          &lt;/div&gt;
  </code></pre>
  
  <p>to  my surprise (or ignorance) - the GUID is being shown instead of ID
  <img src="https://i.stack.imgur.com/fQYfO.png" alt="GUID is shown as ID"></p>
  
  <p>and apart from that - when I enter a value in that field (1,2 or any integer), I still get the message "The field ID must be a number."</p>