I have a model for a view. This view contains a an @Html.DropDownList whose values are in a model. How can I have my view take both model for different parts of the program?
For example, I have
@model IEnumerable<projectname.mymodel>
@{
ViewBag.Title = "my title"
}
<!--This should use a different model-->
<p>@Html.DropDownList(m =>m.name), new set(Model.list, "value", "key"))
If I have model1 and model2(connects to database)-all stored in the Model folder; and a big model class as something like
public class MyViewModel {
public model1 var1 { get; set; }
public IEnumerable<projectname.Model.model2> var2 { get; set; }
}
And i call this model in my view:
@model ProjectName.Models.Models
How do I reference an item in model1 or model2?
Just pass a new class as model to your view which contains all the data you need:
Another approach would be to pass the list in the Viewbag: