Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6166439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:20:22+00:00 2026-05-23T22:20:22+00:00

I have a table with the following structure GUID uniqueidentifier with default value newid(),

  • 0

I have a table with the following structure

GUID uniqueidentifier with default value newid(), and set as primary key
ID int
Description varchar(max)

I created an Entity Model using visual studio, and generated the views for editing/deleting etc (mvc scaffolding)

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..

So, when I click the “Edit” link, the url is

http://localhost:10871/admin/Edit/e7d0c5ee-7782-411f-920e-7b0d93c924e1

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?

Thanks

—Code—

Edit.cshtml

@using (Html.BeginForm()) {
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>Domain</legend>

        @Html.HiddenFor(model => model.GUID)

        @Html.HiddenFor(model => model.ID)

        <div class="editor-label">
            @Html.LabelFor(model => model.Description)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Description)
            @Html.ValidationMessageFor(model => model.Description)
        </div>

        <p>
            <input type="submit" value="Save" />
        </p>
    </fieldset>
}

<div>
    @Html.ActionLink("Back to List", "Index")
</div>

–AdminController.cs–

// GET: /Admin/Edit/5

public ActionResult Edit(Guid id)
{
    Domain domain = db.Domains.Single(d => 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);
}

Edit2
In response to a comment by ZippyV, I added the following code in Edit.cshtml

<div class="editor-label">
            @Html.LabelFor(model => model.ID)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.ID)
            @Html.ValidationMessageFor(model => model.ID)
        </div>

to my surprise (or ignorance) – the GUID is being shown instead of ID
GUID is shown as ID

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.”

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T22:20:23+00:00Added an answer on May 23, 2026 at 10:20 pm

    The problem comes from the fact that you have a property called ID on your view model:

    public class Domain
    {
        public int ID { get; set; }
        ...
    }
    

    and at the same time you have a route parameter called id in your Edit controller action:

    public ActionResult Edit(Guid id)
    {
        ...
    }
    

    Now here’s what happens: The Html helpers (such as TextBoxFor, HiddenFor, …) always first looks in the model state when binding a value (i.e. query string parameters, route values) and only at the end it looks at the value in the model. That’s how all Html helpers work and it is by design.

    So you have the following:

    @Html.HiddenFor(model => model.ID)
    

    The ID is taken NOT from the model but from your Route data (which is a Guid as specified in your action parameter). That’s why it is very dangerous to use properties in the view model and action parameters that have the same name.

    One possible workaround would be to rename your action parameter to something else:

    public ActionResult Edit(Guid domainId)
    {
        Domain domain = db.Domains.Single(d => d.GUID == domainId);
        return View(domain);
    }
    

    Of course now your routes might need to be adapted or use query string parameters: controller/edit?domainId=d578b4b7-48ec-4846-8a49-2120c17b6441 to invoke the Edit action.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have table with following structure id int auto increment, primary key uid int
I have following table structure: Table: Plant PlantID: Primary Key PlantName: String Table: Party
I have a table with the following structure: id int(11), name varchar(250) I have
I have a table with the following structure uid sid eid Key value 1
I have following table structure: CREATE TABLE pilot_groups ( id INT PK, name VARCHAR(50),
I have a table with the following structure, FIELD TYPE EXTRA faciltiy_id int auto_increment(Primary
I have a table with the following structure key1 varchar(255) key2 varchar(255) value decimal(6,2)
I have a table with a structure like the following: LocationID AccountNumber long-guid-here 12345
I have a table with the following structure id(int) | col1(int) | col2(int) |
I have the following table structure CREATE TABLE `table` ( `id` int(11) NOT NULL

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.