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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:47:54+00:00 2026-05-15T23:47:54+00:00

I’m following Scott Guthries MVC tutorial ( http://nerddinnerbook.s3.amazonaws.com/Part6.htm ) and there’s something I don’t

  • 0

I’m following Scott Guthries MVC tutorial (http://nerddinnerbook.s3.amazonaws.com/Part6.htm) and there’s something I don’t understand.

The Controller class called DinnersController has the following Create methods:

    public ActionResult Create()
    {
        Dinner dinner = new Dinner()
        {
            EventDate = DateTime.Now.AddDays(7)
        };

        return View(new DinnerFormViewModel(dinner));
    }

    [AcceptVerbs( HttpVerbs.Post)]
    public ActionResult Create(Dinner dinner)
    {
        if (ModelState.IsValid)
        {
            try
            {
                dinner.HostedBy = "SomeUser";
                dinnerRepository.Add(dinner);
                dinnerRepository.Save();

                return RedirectToAction("Details", new { id = dinner.DinnerID });
            }
            catch
            {
                foreach (var violation in dinner.GetRuleViolations())
                    ModelState.AddModelError(violation.PropertyName, violation.ErrorMessage);                    
            }
        }

        return View(new DinnerFormViewModel(dinner));
    }

The first method causes the page Create.aspx to be shown which displays form data for the object type ‘DinnerViewFormModel’ i.e.

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<NerdDinner.Controllers.DinnerFormViewModel>" %>

The class ‘DinnerViewFormModel’ contains a property called ‘Dinner’ so displaying the relevant information for Dinner type objects is done by calling:

<label for="Title">Title:</label>
<%= Html.TextBox("Title", Model.Dinner.Title) %>

I understand whats going on so far. However, Create.aspx contains a submit type button:

<input type="submit" value="Create" />

When the button is clicked, the following method is called:

    [AcceptVerbs( HttpVerbs.Post)]
    public ActionResult Create(Dinner dinner)

What I don’t understand is, If the form’s Model data is a ‘DinnerViewFormModel’ object, how does MVC know what ‘Dinner’ object needs to be passed to the Create method?

Please could someone enlighten me? Thanks

  • 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-15T23:47:55+00:00Added an answer on May 15, 2026 at 11:47 pm

    AFAIK, MVC just tries to map the properties that are available in the POST to the parameter that it is provided. Because of that, it does not need to know about the type, it just creates the object with the default constructor and maps the form values to the created object – and that is what you get as the method’s parameter value.

    BTW: You’ll also notice that the view output does not contain any reference to the Dinner or DinnerFormViewModel classes.

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

Sidebar

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I have just tried to save a simple *.rtf file with some websites and
In order to apply a triggered animation to all ToolTip s in my app,
I am currently running into a problem where an element is coming back from
Basically, what I'm trying to create is a page of div tags, each has
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,

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.