I think it’s something basic yet I can’t figure it out. Would appreciate some help.
Lets say we have two tables: Tv and Shows.
Shows are connected to Tv table by a TvId field.
Now in our MVC application we obviously have the models to match the two tables.
Now… I need to add a new Show !
I go to a web form, select one of the Tvs and want to add a show.
When I”m on the “New show” form that uses a Shows model.. how can I get access and pass the TvId that this show’s going to be created for ?
I bound all data fields to the Show model but can’t figure out how to connect a new show to its “Tv”.
In your controller, you could do something like create a new model called ShowWithTv – something like this:
Then populate this with the Show details (probably blank, but might have default values), and the TV.
Then in your view change the “Inherits” at the top to be your new ShowWithTv model.
Then you will have access in the view to do this:
Model.TV.{property here}