开发者

ASP.NET MVC Dropdown list on change to cause postback without Javascript

Is it possible to cause a postback to an action from changing your selection in a dropdown list without using JavaScript?

I remember when using the ASP.NET Forms dropdown list control, there was a property that when set would cause a postback on chang开发者_如何学JAVAe, did this work without JS? - If so, how?

Many thanks, Kohan.


You can achieve the postback effect using jQuery. JavaScript in some form or another is required for automatic postbacks. Even ASP.NET uses JavaScript in the background to implement the AutoPostBack property.

<script type='text/javascript'\> 
  $('#dropDown').change(function () {
    $(this).parents('form').submit();
  });
</script>


You need JavaScript to automatically post back data. You don't have to write it, but you still need it. You can post without JavaScript (someone pressing a submit button), but not automatically.

I believe what you are thinking of is the AutoPostBack property.


Do this:

More here:

How do you submit a dropdownlist in asp.net mvc


Complete script which worked for me

 @Html.DropDownList("Projects", Model.Projects, new { 
 style = "Height: 25px; width: 225px;", 
 onchange = "$(this).parents('form').submit();" })
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜