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

  • Home
  • SEARCH
  • 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 6321013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:04:31+00:00 2026-05-24T16:04:31+00:00

I have two edit Action methods, one for HttpGet and one for HttpPost. The

  • 0

I have two edit Action methods, one for HttpGet and one for HttpPost. The HttpGet method takes an id parameter, retrieves the appropriate object, and displays it for editing. The HttpPost method takes a parameter that should be the edited object; however, the ids do not match. Why is that mismatch occurring? I’ve included the code for my Edit.cshtml view, and for my two Action Methods.

The View:

@model WebApplicationPbiBoard.Models.Sprint

@{
    ViewBag.Title = "Edit";
}

<h2>Edit</h2>

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

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

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

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

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

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

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

The Action Methods:

 //
        // GET: /Sprint/Edit/5

        public ActionResult Edit(int id)
        {
            var sprint = Db.GetById(id);
            return View(sprint);
        }

        //
        // POST: /Sprint/Edit/5

        [HttpPost]
        public ActionResult Edit(Sprint editedSprint)
        {
            if (ModelState.IsValid)
            {
                Db.Save(editedSprint);
                return RedirectToAction("Index");
            }
            else
                return View(editedSprint);            
        }

Here’s the GetById method. It’s pretty much a wrapper around the NHibernate ISession.GetById method.

public T GetById(int id)
        {
            return Session.Get<T>(id);
        }
  • 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-24T16:04:32+00:00Added an answer on May 24, 2026 at 4:04 pm

    Here’s my solution. Thanks to everyone who helped me with debugging it.

    The problem was that, to adhere to NHibernate best practices, the setter for my id property was private. That meant that the controller couldn’t set it in the reconstructed model object, so the id was the default value of 0. To solve the problem, I passed the id in as a parameter to the controller and found the right object in my repository, which I then manually updated. Here’s the code:

    [HttpPost]
    public ActionResult Edit(int id, DateTime start, DateTime end)
    {
        //get the right model to edit
        var sprintToEdit = Db.GetById(id);
    
        //copy the changed fields
        sprintToEdit.Start = start;
        sprintToEdit.End = end;
    
        if (ModelState.IsValid)
        {
            Db.Save(sprintToEdit);
            return RedirectToAction("Index");
        }
    
        else
            return View(sprintToEdit);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two Edit User Action methods. The first populates a checkbox correctly with
I have a Controller with two Edit methods (see below). When I submit the
If two users edit the same wiki topic, what methods have been used in
In Java, we have two ways to implement actionPerformed: One actionPerformed method per class:
I have two test method calling to controller: This one passed: [Test] public void
In my Asp.net MVC app, I have two methods on a controller, one for
I have an asp.net view which has two partial views. One for edit information
I have two view controllers in a tabbar which can both edit data. Therefore,
EDIT: I also have access to ESXLT functions. I have two node sets of
EDIT: I have fixed all but two warnings now, so thank you all for

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.