Returning a list to strongly typed view using viewbag?

Q is not a customer, but a sequence of customers. Therefore, when you say ViewBag. Customer = q the ViewBag.

Customer property becomes of type IEnumerable.

Q is not a customer, but a sequence of customers. Therefore, when you say ViewBag. Customer = q;, the ViewBag.

Customer property becomes of type IEnumerable, which, quite naturally, does not have a CustomerName property.

I think you can make this a bit better. First - create a new class called a ViewModel. Add this to your models folder, call it for ex.

CustomerSitesViewModel. Cs In it, add a definition for public IEnumerable Customers {get;set;} public IEnumerable CustomerSites {get;set;} Or you can create a ViewModel CustomerSiteViewModel. Cs which contains public Customer CustomerDetails {get;set;} public CustomerSite CustomerSiteDetails {get;set;} You could name the fields Customer and CustomerSite but I didn't do that for demo purposes so you don't get stuck in a recursive loop not realizing which one to call.

Then your view (to view one) is @model CustomerViewViewModel or if you need a list @model IEnumerable This is the preferred way as opposed to ViewBag data. It's strongly typed. Easier to follow, and less error prone.

First - create a new class called a ViewModel. Add this to your models folder, call it for ex. You could name the fields Customer and CustomerSite but I didn't do that for demo purposes so you don't get stuck in a recursive loop not realizing which one to call.

This is the preferred way as opposed to ViewBag data. It's strongly typed. Easier to follow, and less error prone.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions