ASP.NET MVC autopostback下拉不起作用

时间:2010-07-06 19:36:15

标签: asp.net asp.net-mvc drop-down-menu autopostback

使用以下代码:

<script type="text/javascript" src="../../Scripts/jquery-1.4.1.js" />
<script type="text/javascript">
    $(function () {
        $('#selectOptions').change(function () {
            $(this).parents('form').submit();
        });
    });
</script>

...

    <% using (Html.BeginForm("PostedValue", "Home"))
   { %>

<%: Html.DropDownList("selectOptions", new List<SelectListItem> 
                                 { new SelectListItem{ Text="1",  Value="1"},  
                                   new SelectListItem{ Text="2",  Value="2"},  
                                   new SelectListItem{ Text="3",  Value="3"}},
                                 "Select List")%>
<%} %>
</div> </body>
</html>

我做错了什么?

1 个答案:

答案 0 :(得分:0)

当我执行以下操作时,它可以正常工作

                                        {new SelectListItem {Text =“1”,Value =“1”},                                        新的SelectListItem {Text =“2”,Value =“2”},                                        新的SelectListItem {Text =“3”,Value =“3”}},                                                      “选择列表”,**新{onchange =“$(this).parents('form')。submit()”**})%&gt;                                           

我想知道为什么$ function()不起作用..