提交部分视图失败

时间:2013-12-13 02:21:52

标签: jquery ajax asp.net-mvc

我一直试图在本教程之后实施这个级联下拉数小时而没有运气:http://www.codeproject.com/Articles/258172/Simple-Implementation-of-MVC-Cascading-Ajax-Drop-D
问题不在于我的控制器,也不在于我的下拉列表更改时触发的jquery事件。我假设问题在于行$(this).parents('form').submit();

以下是我的问题发生的视图

@model gcaMusicExchange.ViewModels.CategoryResultsViewModel
@using (Ajax.BeginForm("SelectMake", "PerformancePartResults", new AjaxOptions {
         UpdateTargetId = "ModelControl" }))
{
    @Html.DropDownListFor(P => P.SelectedMake, new SelectList(Model.Makes, "id", "Name", ""))
}
<script type="text/javascript">
    $('#SelectedMake').change(function () {
    $(this).parents('form').submit();
});

这是actionresult

    [HttpPost]
    public ActionResult SelectMake(int SelectedMake)
    {
        if (SelectedMake != -1)
        {
            using (var context = new JDMExchangeEntities())
            {
                List<VehicleModel> models = context.VehicleModels.Where(p => p.MakeId == SelectedMake).ToList();

                SelectList selectModels = new SelectList(models);

                return PartialView("ModelsUserControl", selectModels);
            }
        }

        ViewModels.CategoryResultsViewModel vM = new ViewModels.CategoryResultsViewModel();
        vM.SelectedMake = (int)SelectedMake;

        return View(vM);
    }

如果我在动作结果上设置了一个断点,它就永远不会被执行。

0 个答案:

没有答案