I have the following problem: After exchanged value of the DropDownList, call the Create action in the controller using the script, the model is updated correctly, but did not show changes in View. Does not display any change in View, it remains unchanged although the model has changed. Please tell me where I'm wrong. Thank You.
Controller:
public ActionResult Create(int? id)
{
IEnumerable<Instructor> selIns = db.Instructors.Where(x => x.ID == id);
var model = new CreateDepartmentViewModel
{
Department = new Department(),
Instructors = selIns,
};
return View(model);
}
View:
@if (Model.Instructors != null)
{
<h3>
Instructors
</h3>
<table class="table">
<tr>
<th>Name</th>
<th>Grade</th>
</tr>
@foreach (var item in Model.Instructors)
{
<tr>
<td>
@item.FullName
</td>
<td>
@Html.DisplayFor(modelItem => item.HireDate)
</td>
</tr>
}
</table>
}
….
@Html.DropDownListFor(x => x.Department.InstructorID, Model.InstructorIds, htmlAttributes: new { @id = "intructors", @class = "form-control" })
…..
$(document).ready(function () {
$("#intructors").change(function () {
var idselect = $("#intructors").val();
$.get("/Department/Create", { id: idselect }, function (data) {
});
});
});
Create()method. What are you expecting?id="someValue"?