Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

MVC 4: Several Models in one Model causing an error

Posted on 2013-06-12
1
Medium Priority
?
433 Views
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?
0
Comment
Question by:AmbassadorSpock
[X]
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

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

I made to modify the AccountController, it was:

        [HttpPost]
        public ActionResult Create(Account account)
        {
            if (ModelState.IsValid)
            {
                context.Accounts.Add(account);
                context.SaveChanges();
                return RedirectToAction("Index");  
            }

            return View(account);
        }

After I modified it to the below, it worked.

        [HttpPost]
        public ActionResult Create(CreateAccountViewModel CreateAccount)
        {
            if (ModelState.IsValid)
            {
                context.Accounts.Add(CreateAccount.AccountModel);
                context.SaveChanges();
                return RedirectToAction("Index");  
            }

            return View(CreateAccount);
        }
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
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. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

604 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