I’m new to the .net framework but not to programming. I used the simple Crud generation with .net/c# and on the create view I would like to be able to have a dropdown list generated from a different model. I’m not sure how to achieve this with c#.net Any help would be greatly appreciated.
Thanks!
Hi user1121777 (couldn’t resist)
If your drop-down list comes from a separate model (I do that myself), you can instantiate the context related to model#2, query for that drop-down list data as a No-Tracking query and then dispose that context.
How you do a no-tracking query is different if you are using an ObjectContext from how you do it with a DbContext.
For DbContext, you can use the AsNoTracking method extension on a linq query.
For ObjectCOntext it’s a PIA. 🙂 Check this old article I wrote and if you search for the term “notracking” you’ll see the basic pattern for that.
When you make a selection from the drop-down list, you can then use the key value of the selection and apply that to the related foreign key property of the object you are editing.
HTH
Julie