MVC 4: Several Models in one Model causing an error

Posted on 2013-06-12
Last Modified: 2013-06-12
I have several Models defined such as RescueFormsAdministration.Models.Account that I have given the name AccountModel and a wrapper Model RescueFormsAdministration.Models.CreateAccountViewModel that contains the Account and other Models in order to pass it to one View. This works until I run it and then I get the error below:
"The model item passed into the dictionary is of type 'RescueFormsAdministration.Models.Account', but this dictionary requires a model item of type 'RescueFormsAdministration.Models.CreateAccountViewModel'. "

Does anyone know how to fix the problem?
Question by:AmbassadorSpock
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment

Accepted Solution

AmbassadorSpock earned 0 total points
ID: 39242131
I found my own answer:

I made to modify the AccountController, it was:

        public ActionResult Create(Account account)
            if (ModelState.IsValid)
                return RedirectToAction("Index");  

            return View(account);

After I modified it to the below, it worked.

        public ActionResult Create(CreateAccountViewModel CreateAccount)
            if (ModelState.IsValid)
                return RedirectToAction("Index");  

            return View(CreateAccount);

Featured Post

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User art_snob ( encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question