Passing a string from view to controller in ASP.NET MVC Razor -


i've got asp.net mvc razor application. in application have multiselect control (which dropdown can select multiple items from). have subscribed "close" event of control when closed, passes string of comma separated integers controller. however, although method in controller being called, value being passed null. have tested event , know string being generated correctly. here code in event handler:

    `function close() {         var alerttypeids = $("#alertmultiselect").val().tostring();         //alert("this alerttypeid: " + alerttypeids);         $.post('@url.action("subscribetoalerts")', { value: alerttypeids }, function (result) {             alert("the value sent server");         });     };` 

here controller code:

`public void subscribetoalerts(string alerttypeids)     {         bool issubscribedtonewitem = false;         bool issubscribedtonewcustomer = false;         bool issubscribedtonewsupplier = false;          if (alerttypeids.contains('1')){             issubscribedtonewitem = true;         }         if (alerttypeids.contains('2')) {             issubscribedtonewcustomer = true;         }         if (alerttypeids.contains('3')) {             issubscribedtonewsupplier = true;         }          var subscriptionrepository = new bmtool.persistance.subscriptionrepository();         var userrepository = new bmtool.persistance.userrepository();          ilist<bmtool.models.user> user = userrepository.getuser("anorkin@daymon.com");         int associateid = user[0].associateid;          subscriptionrepository.updatesubscriptionforuser(associateid, issubscribedtonewitem, issubscribedtonewcustomer, issubscribedtonewsupplier,             issubscribedtobmterminated, issubscribedtobmchange, issubscribedtoitemcategorychange);     }` 

now know string alerttypeids being generated correctly in handler. know controller method being hit. however, value being passed controller (alerttypeids) null. want note aware sloppy code. wanted make sure i'm not passing in null before go through work of writing code may have throw away.

it have instead; notice new data name:

 $.post('@url.action("subscribetoalerts")', { alerttypeids: alerttypeids },       function (result) {             alert("the value sent server");      }); 

the name of field needs match name in controller, have use alerttypeids.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -