c# - how to pass the value of dropdownlist to controller in asp.net when on-change event triggers -


this script in view when dropdownlist wth id = #apsuppliergroupid triggers on-change event , give selected value var $apsuppliergroupid.

<script><script> $(function () {     $('#apsuppliergroupid').change(function () {         var $apsuppliergroupid = $("#apsuppliergroupid option:selected").val();         $('#apsupplier1').html($apsuppliergroupid);      }); });     

this controller:

public class acptnvcecontroller : controllerbase<aptransactionheaderentity, aptransactionheader> {     public acptnvcecontroller()     {      }      public actionresult event()     {         string suppliergroupid = "";          suppliergroupid = $apsuppliergroupid; //here! how can pass variable script $apsuppliergroupid  value suppliergroupid controller?         return view();     }  } 

how can pass value of var $apsuppliergroupid controller?

please help! responses appreciated. thanks!

your method needs parameter accept posted value

public actionresult event(int id) {     // id contain value of selected option } 

and script can be

var url = '@url.action("event", "acptnvce")'; $('#apsuppliergroupid').change(function () {     $.post(url, { id: $(this).val() }, function(response) {         // returned data         // $('#apsupplier1').html(response); ??     }); }); 

or replace $.post() $.get() depending on needs, or more control, use $.ajax()


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -