Hi I am working in a MVC 3 application. I have a Create Form with following code.
@model Xrm.Student
@{
ViewBag.Title = "Create Student Record";
}
@using (Html.BeginForm("Create", "Student", FormMethod.Post))
{
<div class="editor-label">
@Html.LabelFor(model => @Model.FirstName)
</div>
<div class="editor-field">
@Html.EditorFor(model => @Model.FirstName)
@Html.ValidationMessageFor(model => @Model.FirstName)
</div>
<div>
<input id="Submit1" type="submit" value="Submit" />
</div>
}
I want to add a new drop down under Firsname field which should be populated with pubjects. Subject is different Entity. I could be very easy, but I am newbie with MVC so I just stuck here. Can anyone please suggest me the way to achieve it.
Thanks and Regards
I would define a view model:
and then have your controller populate and pass this view model to the view:
and finally have your view strongly typed to the view model:
The
"Id"and"Name"values I used for the SelectList must obviously be existing properties on yourSubjectclass that you want to be used as respectively binding the id and the text of each option of the dropdown.