4
我即将在MVC 3中创建级联下拉列表。Logik很简单,对于每个位置可能有很多员工,因此我可以找出如何实现它的最佳方式是下拉列表。级联下拉MVC 3
我有什么现在的问题是:
1清单在与位置begninnging填满。和变化,我可以当我尝试发送员工在与ID和名称没有什么happend数据放入第二个我的员工名单,但我传送的数据是Enumrable日期”
控制器代码:
public ActionResult Months(string locId)
{
var k = service.getEmployeeForLocation(Int32.Parse(locId))
.ToList()
.Select(x => new
{
Value = .EmployeeId,
Text = x.Name
});
return Json(k,JsonRequestBehavior.AllowGet);
}
查看:
<tr>
<td>Choose your closest location :
@Html.DropDownListFor(x => x.SelectedLocation, Model.Locations)</td>
<td>Choose your closest location :
@Html.DropDownListFor(x => x.SelectedEmployee,
Enumerable.Empty<SelectListItem>(), "-- select month --")
</tr>
的Javascript
</script>
<script type="text/javascript">
$('#SelectedLocation').change(function() {
var selectedLocation = $(this).val();
if (selectedLocation != null && selectedLocation != '') {
$.getJSON('@Url.Action("Months")', { locId: selectedLocation },
function (employee) {
var EmployeeSelect = $('#SelectedEmployee');
// monthsSelect.empty();
$.each(employee, function (index, employee) {
EmployeeSelect.append($('<option/>', {
value: employee.value,
text: employee.text
}));
});
});
}
});
</script>
哦,我的上帝....我总是忘记JS对我自己是大小写敏感的.../facepalm。非常感谢。我愿意在VS – Timsen 2011-12-27 01:22:55
@Timsen没有问题,节日快乐! – Craig 2011-12-27 01:44:15