最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin4浏览0评论

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 change, did this work without JS? - If so, how?

Many thanks, Kohan.

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 change, did this work without JS? - If so, how?

Many thanks, Kohan.

Share Improve this question edited Dec 22, 2010 at 15:51 Leniel Maccaferri 102k46 gold badges378 silver badges493 bronze badges asked Dec 22, 2010 at 15:41 4imble4imble 14.4k15 gold badges76 silver badges132 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 6

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 mvc

Complete script which worked for me

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

评论列表(0)

  1. 暂无评论