© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
10 replies
Larsa

✅ 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
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
Game
model which has 2 FK's
Developer
Developer
and
Publisher
Publisher
- within my
create()
create()
View for the
Game
Game
Model I wish to have a drop down list of
Developers
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:

                        <div class="form-group">
                         <label asp-for="DeveloperId" class="control-label"></label>
                        <select asp-for="DeveloperId" class="form-control" asp-items="ViewBag.Developer"></select>
                         <span asp-validation-for="DeveloperId" class="text-danger"></span>
                        </div>
                        <div class="form-group">
                         <label asp-for="DeveloperId" class="control-label"></label>
                        <select asp-for="DeveloperId" class="form-control" asp-items="ViewBag.Developer"></select>
                         <span asp-validation-for="DeveloperId" class="text-danger"></span>
                        </div>


Any help is greatly appreciated, thank you.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Passing DateOnly to controller
C#CC# / help
2y ago
❔ Viewing List from ViewBag
C#CC# / help
4y ago
✅ My all the field not passing to the controller from view. Please take a look
C#CC# / help
2y ago
✅ Kinda new to MVC/C#/Razor - Need some help passing data from Model -> Controller
C#CC# / help
3y ago