0

這裏是我的代碼:爲什麼我的下拉列表不提交表單?

<div class="center"> 
    <p> Choose item:</p> 
    <div class="dropdown"> 
     @using (Html.BeginForm("Start", "Home", FormMethod.Post, new { name = "form", id = "form" })) 
     { 
      @Html.DropDownListFor(x => x.SelectedId, @Model.ViewJaren, 
       new 
       { 
        onchange = "this.parentNode.form.submit()" 
       } 
      ) 
     } 
    </div> 
</div> 

一直試圖得到它的工作,但不能弄明白。我得到onchangedocument.getElementById("form")一起工作。但沒有價值通過。我得到一個空白頁面。

+1

爲什麼在'onchange'前面有'@'? – Coda17 2015-04-02 12:29:17

+1

你沒有提交表單*到*任何東西。沒有任何動作可以發佈,您將動作和控制器設置爲'null' – DLeh 2015-04-02 12:31:21

+0

我編輯了代碼,考慮到您的評論仍然沒有進展。不知道爲什麼@在那裏。我相應地編輯了我的帖子。 – ManyQuestions 2015-04-02 12:37:14

回答

0

爲什麼不把它分開。

<script> 
$(document).ready(function(){ 
    $('#@Html.IdFor(x => x.SelectedId)').change(function(e){ 
     $(this).closest('form').submit(); 
    }); 
}); 
</script>