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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -