mvc accessing a different model from the strongly typed provided
so I'm writing to see what the best way is to de开发者_Python百科al with this ish that I have.
I have 3 models and a view that has a strongly typed using one of the models.
Here are the models:
public class Car{
public int CarId
}
public class User{
public int UserId
}
public class UserCar{
public int UserId
public int CarId
:
:
}
View would be strongly typed with Cars model to provide all the details of the car when the view is visited. But in it I want to have an indicator (maybe a text) that says that the User already has/owns the car which will depend on the UserCar model mapping.
Any thoughts?
I think you might be able to solve this by passing a strongly typed UserCar Model instead of the cars model and updating the UserCar model to have instances of the User and Car objects for example:
public class UserCar{
public User UserId
public Car CarId
:
:
}
this way you can check if userId is null as an indicator.
Just an idea...
精彩评论