passing data in mvc

What would an mvc model look like that is passing a list like for a dropdownlist and also passing other data like firstname lastname? Do you have to use viewmodel
green_thumb_98Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

green_thumb_98Author Commented:
Is the answer just to use viewdata for passing the dropdownlist items?  Then use the model for everything else like firstname, lastname, etc.?
0
Craig WagnerSoftware ArchitectCommented:
If you're looking for a "right" answer to this question you're going to be disappointed because there isn't one.

You could use ViewData to pass the drop down items and a model to pass the editable fields, or you could use a viewmodel to pass everything. It really just depends on how you want to handle it and what the standards of your organization are for this type of thing.

If it were entirely up to me I'd create a viewmodel to pass everything. That way I get a strongly-typed view and get Intellisense for all the items in the viewmodel when I'm writing the view.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
angus_young_acdcCommented:
You can use the view model to pass through the list, so for example your model would have

List<TypeOfObject MyListOfItems { get; set;}

And you could then call that whenever needed from your controller, and assign it in the view.

EG controller
var myModel = new MyViewModel();
myModel.MyListOfItems = [Whatever way you're getting your list].

And in your view (going off memory) you could just assign it out as @html.DropDownList(model => model.MyListOfItems, "Default item")
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.