Asp.net mvc 控制网格的MVC下拉列表-使其工作的最佳方法是什么?

Asp.net mvc 控制网格的MVC下拉列表-使其工作的最佳方法是什么?,asp.net-mvc,Asp.net Mvc,我在客户端有一个下拉列表。当用户做出选择时,我的jquery脚本提取选择的新值。 但是下面的代码不起作用,因为我无法确定如何将所选值发送回控制器。我不确定发送参数的语法,因为我使用的是分页参数。也许我应该做一个Ajax调用 景色看起来像 <asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server"> BankHoliday </asp:Content> <asp:

我在客户端有一个下拉列表。当用户做出选择时,我的jquery脚本提取选择的新值。 但是下面的代码不起作用,因为我无法确定如何将所选值发送回控制器。我不确定发送参数的语法,因为我使用的是分页参数。也许我应该做一个Ajax调用

景色看起来像

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    BankHoliday
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="AdminAccountsContent" runat="server">
    <% using (Html.BeginForm())
       {%>
       <%: Html.AntiForgeryToken() %>
        <h3>Bank Holiday Administration</h3>
        <p>Select the year: <%: Html.DropDownListFor(model => model.SelectedYear, Model.YearList)%></p>
            <fieldset>
            <legend>Enter the bank holidays here:</legend>
            <table>
                <tr><td colspan="3"><i>You can find the bank holiday dates on this <a target="_blank" href="http://www.year-planner-calendar.wanadoo.co.uk/">website</a>.</i> </td></tr>
                <tr>
                    <th>Bank Holiday</th>
                    <th>Date</th>
                    <th>Notes</th>
                </tr>
                <% foreach (var bankHolidayExtended in Model.BankHolidays)
                   { %>
                    <% Html.RenderPartial("BankHolidaySummary", bankHolidayExtended); %>
                <% } %>
               <tr>
                    <td align="center" colspan="3" style="padding-top:20px;">
                        <input type="submit" value="Save"/>
                    </td>
                </tr>
                 <% if (ViewData["UpdatedFlag"] == "True")
                   { %>
                   <tr>
                        <td id="confirmationMessage" colspan="3">
                            At time <% Response.Write(DateTime.Now.ToString("T")); %> - Details have been successfully saved 
                        </td>
                   </tr>
                   <%}
                   else if (ViewData["UpdatedFlag"] == "False")
                   {%>
                   <tr>
                        <td id="Td1" colspan="3">
                            At time <% Response.Write(DateTime.Now.ToString("T")); %> - ERROR! Details have NOT been saved 
                        </td>
                   </tr>
                   <%} %>
            </table>
            </fieldset>
        <% } %>
        <script language="javascript" type="text/javascript">
            $(function () {
                $("#SelectedYear").change(function () {
                    var year = $("#SelectedYear").val();
                    $("#wholepage").load("/BankHoliday/Create/" + year);
                });
            });

    </script>
</asp:Content>
控制器看起来像

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    BankHoliday
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="AdminAccountsContent" runat="server">
    <% using (Html.BeginForm())
       {%>
       <%: Html.AntiForgeryToken() %>
        <h3>Bank Holiday Administration</h3>
        <p>Select the year: <%: Html.DropDownListFor(model => model.SelectedYear, Model.YearList)%></p>
            <fieldset>
            <legend>Enter the bank holidays here:</legend>
            <table>
                <tr><td colspan="3"><i>You can find the bank holiday dates on this <a target="_blank" href="http://www.year-planner-calendar.wanadoo.co.uk/">website</a>.</i> </td></tr>
                <tr>
                    <th>Bank Holiday</th>
                    <th>Date</th>
                    <th>Notes</th>
                </tr>
                <% foreach (var bankHolidayExtended in Model.BankHolidays)
                   { %>
                    <% Html.RenderPartial("BankHolidaySummary", bankHolidayExtended); %>
                <% } %>
               <tr>
                    <td align="center" colspan="3" style="padding-top:20px;">
                        <input type="submit" value="Save"/>
                    </td>
                </tr>
                 <% if (ViewData["UpdatedFlag"] == "True")
                   { %>
                   <tr>
                        <td id="confirmationMessage" colspan="3">
                            At time <% Response.Write(DateTime.Now.ToString("T")); %> - Details have been successfully saved 
                        </td>
                   </tr>
                   <%}
                   else if (ViewData["UpdatedFlag"] == "False")
                   {%>
                   <tr>
                        <td id="Td1" colspan="3">
                            At time <% Response.Write(DateTime.Now.ToString("T")); %> - ERROR! Details have NOT been saved 
                        </td>
                   </tr>
                   <%} %>
            </table>
            </fieldset>
        <% } %>
        <script language="javascript" type="text/javascript">
            $(function () {
                $("#SelectedYear").change(function () {
                    var year = $("#SelectedYear").val();
                    $("#wholepage").load("/BankHoliday/Create/" + year);
                });
            });

    </script>
</asp:Content>
public ActionResult ListHistoryGridSortOptions排序,int?页面,int?EmployeeStatusId { if Request.QueryString[lastPersonMessage]==null ViewData[LastPersonMessage]=string.Empty; 其他的 ViewData[LastPersonMessage]=Request.QueryString[LastPersonMessage]

    IEnumerable<EmployeeExtended> employees = null;

    switch (EmployeeStatusId.GetValueOrDefault(1))
    {
        case 1: employees = EmployeeExtended.GetAllFormerEmployees();
            break;
        case 2: employees = EmployeeExtended.GetAllOnNoticeEmployees();
            break;
        case 3: employees = EmployeeExtended.GetAllCurrentEmployees();
            break;
    }
    if (sort.Column != null)
    {
        employees = employees.OrderBy(sort.Column, sort.Direction);
    }
    int pageLength = Convert.ToInt32(ConfigurationManager.AppSettings["EmployeeListPageLength"].ToString());
    employees = employees.AsPagination(page ?? 1, pageLength);
    ViewData["sort"] = sort;
    return View(employees);
}

您可以在Ajax.BeginForm调用中使用它,但Url不会更改..-意味着:每次刷新它时,它都会将您返回到默认页面

我已经做了类似的事情:

<%: Html.DropDownList(Model => Model.SelectedYear, Model.YearList, new { onchange = "location.href='/Controller/Action/'+this.value" }) %>

这将为解决这个问题提供一些基础。如果你想在你的控制器上调用的方法有下面的签名,你会怎么做?公共行动结果ListTistRyGrReReSoopPoint排序,int?页面,int?EngestStestuSud,你可以尝试一些新的东西:{onchange=location.href='/Controller/Action?sort=SomeValue&page=SomeValue&EmployeeStatusId=SomeValue}