我已经广泛研究了这个问题,但无法找出问题所在。我正在尝试使用 MVC4 和 Jquery 为我拥有的页面实现级联下拉菜单,无论我在线使用什么解决方案,我的 ActionResult 参数始终为空。
这是可以正常调用的Javascript:
<script type="text/javascript">
$('.clientnames').on('change', function (e) {
// Retrieve the filter url from the data-filter-url attribute
var filterUrl = $(this).attr('data-filter-url');
// Grab the id of the selected item
var selectedId = $(this).val();
window.alert("filterurl:" + filterUrl + " selectedID:" + selectedId);
// Grab the container that should be updated
var updateContainer = $(this).attr('data-update-container');
// Grab the id of new dropdown
var dataUpdateId = $(this).attr('data-update-id');
var completeUrl = filterUrl + selectedId;
$.get(completeUrl, function (r) {
// Load Partial View using the URL from the data-filter-url attribute
$(updateContainer).html(r);
// This would be used if you wanted to trigger the new dropdown to filter another
if (dataUpdateId != null) {
// Trigger the change event after it is loaded
$(dataUpdateId).trigger('change');
}
});
});
控制器函数,它被调用但值未成功传入:
public ActionResult ImportList(string selectedId)
{
//DO COOL STUFF
}
和观点:
@Html.DropDownListFor(model => model.Clients.DropdownItems, new SelectList(Model.Clients.DropdownItems, "ItemID","ItemName"), new { @class = "clientnames", data_filter_url = Url.Content("~/import/importlist/"), data_update_container = ".dropdown-container", data_update_id = "#SecondItemID" } )
我非常遵循此页面上的建议:http ://www.sidecreative.com/Blog/Entry/Cascading-dropdown-lists-with-MVC4-and-jQuery
尽管我尝试了几种不同的解决方案,但每次该值仍然为空。我对 MVC 和 Jquery 很陌生,所以任何建议都将不胜感激。