Ajax.BeginForm无法提交下拉列表选中的值

时间:2016-06-10 23:02:11

标签: jquery asp.net-mvc forms ajax.beginform

形式:

multimap

searchResult操作:

<div id="_SearchTab">
    @using (Ajax.BeginForm("searchResult", "Maintenance", null, 
        new AjaxOptions {
            InsertionMode = InsertionMode.Replace,
            UpdateTargetId = "gridArea",
            HttpMethod = "Get",
            LoadingElementId = "loading"
        }, new { id = "searchByCriteria"}))
{
<table>
    <tr>
    <td>
     @Html.LabelFor(model => model.UNIT_CD)
                @Html.DropDownListFor(model => model.UNIT_CD, new SelectList(ViewBag.UnitList, "Value", "Text"), "-- Select a Unit --")
    </td> </tr>
    <tr>
    <td>
        @Html.LabelFor(model => model.PROGRAM_CD)
            @Html.TextBoxFor(model => model.PROGRAM_CD)
        </td> </tr>

       </table>
            <div id=" buttonHolder">
    <input id="Search" type="Submit" value="Search"/>
</div>
} 
</div>
<div id="gridArea">
   display data here
</div>

问题是当我提交表单时,[HttpGet] public PartialViewResult searchResult(string unitCode, string programCode) // showed both null in debug mode { // typical Linq stuff, if parameters are null, show all the data in the partial view, if at leastone of the parameters is not null, use it as search criteria } 操作的两个参数都显示为searchResult。我尝试了多种方法,包括以下内容:

null

这:(使用Javascript运行时错误)

<input id="Search" type="Submit" value="Search" 
onclick="javascript:$('searchByCriteria').submit()" />

<input id="Search" type="Submit" value="Search" onclick ="@(Url.Action("searchResult", "Maintenance", new { unitCode = Model.UNIT_CD, programCode = Model.PROGRAM_CD})) "/> 添加到表单参数中,并使用Javascript提交:

onsubmit=return searchForm()

jQuery用于function searchForm() { $("#gridArea").html(""); // Load SearchResult partialview in gridArea div $("#gridArea").load( '@(Url.Action("searchResult", "Maintenance", new { unitCode = Model.UNIT_CD, programCode = Model.PROGRAM_CD}))' ) return false; } 按钮的点击事件

Search

或表单的提交事件

$("#Search").click(
            function () {
                // clear the grid area
                $("#gridArea").html("");
                // Load SearchResult partialview in gridArea div
                $("#gridArea").load(
                    '@(Url.Action("searchResult", "Maintenance", new { unitCode = Model.UNIT_CD, programCode = Model.PROGRAM_CD}))'
                )
        });

以上都不能将参数传递给控制器​​。有人可以帮帮我吗?

1 个答案:

答案 0 :(得分:0)

可能你已经得到了解决方案。虽然你也可以这样走,

[HttpGet]
public PartialViewResult searchResult(string unitCode, string programCode)
{
    unitCode= Request.Form["UNIT_CD"];
    programCode= Request.Form["PROGRAM_CD"];
    ...
}