✅ Passing data from controller to view
Hi guys hoping for some help here.
I have an eCommerce wep app using ASP.NET MVC (7.0) and I want to pass data from a controller to a view. Now I understand I can do this with the
ViewBag
dynamic property or strongly typed view models. The data I want pass belongs to another model entirely and not the model for which the View is for.
I have a Game
model which has 2 FK's Developer
and Publisher
- within my create()
View for the Game
Model I wish to have a drop down list of Developers
in the database to select from. How do I achieve this? Been stuck on this step for a while now and I'm still very new to .NET.
I thought I could do something like this:
Any help is greatly appreciated, thank you.5 Replies
Use strongly-typed models. Always and forever.
Use a DTO if needed
I need to do create a method in my
Developer
controller that can do this?I guess you could have the model be some
That way the view will have only one
@model
You can send the data inside of the GetData
property
And bind the form to PostData
Or you could maybe place your form inside of a partial, that would let you use a different model for itHmm ok - might have to research a little bit to figure out how to do that. Thank you for the suggestions 😊
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.