If I am using a ViewBag which contains a strongly typed object, is there any way on MVC Razor to define (or cast this) so that all the elements of that appear in the IntelliSense?
For example lets say I have
ViewBag.Movies.Name
ViewBag.Movies.Length
I know Movies is of object type Movie, which has the members Name and length
class Movie {
public string Name {get; set;}
public string Length {get; set;}
}
Can I somehow cast this, like I do for model
@model Transactions.UserTransactionDetails
So that the members of Movie become available in Razor?
Use a ViewModel, which contains properties for all the different objects that you view needs
e.g.
Then, have your view use this as it’s model, and you will get intellisense in your view.
That way you are not changing your models, so EntityFramework will not be affected.