0

How do I get the values from multiple models in a single view? Is using ViewModel the correct solution? Creating ParentModel also gives error. Any step-by-step tutorial on this?

5
  • What is the error? Read this: lostechies.com/jimmybogard/2009/06/30/how-we-do-mvc-view-models Commented Sep 11, 2012 at 10:00
  • I have two models (suppose First and Second). I then create a parentmodel: { public int ID { get; set; } public virtual First first{ get; set; } public virtual Second second { get; set; } } In view, I have @model projectName.Models.ParentModel. I want to display attributes of both the table in this view [email protected](model => model.first.address) But I get error like this: The model item passed into the dictionary is of type 'System.Data.Entity.DynamicProxies...', but this dictionary requires a model item of type 'projectName.Models.ParentModel'. Any help? Commented Sep 11, 2012 at 10:19
  • Can you paste the code you where you are passing the model into the view. ? Commented Sep 11, 2012 at 10:20
  • I am new to MVC and don't have clear idea about this.. do I need to create a separate controller as well using the ParentModel? I am not even allowed to do that..(gives error). Commented Sep 11, 2012 at 10:27
  • It depends on your design. But you create a Controller and in your Controller you have a method which is an Action. The Action may be the same name as your View, and you usually do something like return View(model). If the action isn't the name of your View you will do something like View("ViewName", model); Commented Sep 11, 2012 at 10:34

1 Answer 1

1

Create a ViewModel, Check this Creating a View Model

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.