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 812831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:15:50+00:00 2026-05-15T01:15:50+00:00

I am new to MVC, and so am working through the NerdDinner tutorial, here

  • 0

I am new to MVC, and so am working through the NerdDinner tutorial, here. In particular, I’m running into problems with the use of the UpdateModel method, which is explained in the part five of that tutorial. The problem is, when I try to edit the value of a dinner object using the UpdateModel method, the values do not get updated, and no exceptions are thrown.

Oddly, I am not having any trouble with the Create or Delete features that are illustrated in the tutorial. Only the update feature isn’t working.

Below, I have included the Controller code that I am using, as well as the view markup, which is contained in both an aspx View file and an ascx Partial View file.

Here is the code inside my Controller, called DinnerController.cs:

    //
    // GET: /Dinners/Edit/2
    [Authorize]
    public ActionResult Edit(int id)
    {

        Dinner dinner = dinnerRepository.GetDinner(id);

        return View(new DinnerFormViewModel(dinner)); 
    }

    //
    // POST: /Dinners/Edit/2
    [AcceptVerbs(HttpVerbs.Post), Authorize]
    public ActionResult Edit(int id, FormCollection formValues)
    {

        Dinner dinner = dinnerRepository.GetDinner(id);

        try
        {
            UpdateModel(dinner);
            var x = ViewData.GetModelStateErrors(); // <-- to catch other ModelState errors

            dinnerRepository.Save();

            return RedirectToAction("Details", new { id = dinner.DinnerID });
        }
        catch
        {

            ModelState.AddRuleViolations(dinner.GetRuleViolations());

            return View(new DinnerFormViewModel(dinner)); 
        }
    }

The
line with the comment “to catch other ModelState errors” was added after reading a possible solution from another StackOverflow thread, here:

ASP.NET MVC Updatemodel not updating but not throwing error

Unfortunately, that solution didn’t help me.

Here is the corresponding markup in my Dinners/Edit.aspx View:

<asp:Content ID="Main" ContentPlaceHolderID="MainContent" runat="server">

    <h2>Edit Dinner</h2>

    <% Html.RenderPartial("DinnerForm"); %>

</asp:Content>

Here is the corresponding markup in my DinnerForm.ascx Partial View. This Partial View file is also used by the Create feature, which is working fine:

<%=Html.ValidationSummary("Please correct the errors and try again.") %>  

<% using (Html.BeginForm()) { %>

    <fieldset>
        <p>
            <label for="Title">Dinner Title:</label>
            <%=Html.TextBoxFor(model => Model.Dinner.Title)%>
            <%=Html.ValidationMessage("Title", "*") %>
        </p>
        <p>
            <label for="EventDate">EventDate:</label>
            <%=Html.TextBoxFor(model => Model.Dinner.EventDate, new { value = String.Format("{0:g}", Model.Dinner.EventDate) })%>
            <%=Html.ValidationMessage("EventDate", "*") %>
        </p>
        <p>
            <label for="Description">Description:</label>
            <%=Html.TextBoxFor(model => Model.Dinner.Description)%>
            <%=Html.ValidationMessage("Description", "*")%>
        </p>
        <p>
            <label for="Address">Address:</label>
            <%=Html.TextBoxFor(model => Model.Dinner.Address)%>
            <%=Html.ValidationMessage("Address", "*") %>
        </p>
        <p>
            <label for="Country">Country:</label>
            <%=Html.DropDownListFor(model => Model.Dinner.Country, Model.Countries)%>
            <%=Html.ValidationMessage("Country", "*") %>
        </p>
        <p>
            <label for="ContactPhone">ContactPhone #:</label>
            <%=Html.TextBoxFor(model => Model.Dinner.ContactPhone)%>
            <%=Html.ValidationMessage("ContactPhone", "*") %>
        </p>
        <p>
            <label for="Latitude">Latitude:</label>
            <%=Html.TextBoxFor(model => Model.Dinner.Latitude)%>
            <%=Html.ValidationMessage("Latitude", "*") %>
        </p>
        <p>
            <label for="Longitude">Longitude:</label>
            <%=Html.TextBoxFor(model => Model.Dinner.Longitude)%>
            <%=Html.ValidationMessage("Longitude", "*") %>
        </p>
        <p>
            <input type="submit" value="Save"/>
        </p>
    </fieldset>

<% } %>

In any case, I’ve been hitting away at this for hours, and I’m out of ideas. So, I’m hoping someone here can help nudge me in the right direction, in order to figure out what I’m doing wrong.

  • 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-15T01:15:51+00:00Added an answer on May 15, 2026 at 1:15 am

    You got something mixed up. You are sending DinnerFormViewModel to View but trying to receive Dinner.Change your post method like this:

    [AcceptVerbs(HttpVerbs.Post), Authorize]
        public ActionResult Edit(int id, FormCollection formValues)
        {
    
            var dinner=new DinnerFormViewModel(dinnerRepository.GetDinner(id));
    
            try
            {
                UpdateModel(dinner);
                var x = ViewData.GetModelStateErrors(); // <-- to catch other ModelState errors
    
                dinnerRepository.Save();
    
                return RedirectToAction("Details", new { id = dinner.Dinner.DinnerID });
            }
            catch
            {
    
                ModelState.AddRuleViolations(dinner.GetRuleViolations());
    
                return View(new DinnerFormViewModel(dinner)); 
            }
        }
    

    There may be something I missed here, don’t remember DinnerFormViewModel right now. Please check those

    edit: Actually I realized this post doesn’t solve the problem really. The code posted in the question works for me. There is a problem but but not here.

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

Sidebar

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.