c# - Getting data from javascript function on to ASP.NET MVC Controller's Action Method -


i have looked @ many posts on figure out situation not success. i'm trying send data javascript function(dropdownchange()) mvc controllers action method parameter based on dropdown value selected on view. here code:

in .cshtml //code dropdown ....followed //code creating new plan

 <a href="@url.action("actionmethod")">            <i class="sth" id="sth" title="create"></i>       </a> 

in .js file, function dropdown change value

  function dropdownchange(){        var value = parseint($("#dropdownid").val());         $.ajax({            type: "post",            url: '@ url.action("actionmethod", "home")',            contenttype: 'application/json; charset=utf-8',            datatype: "json",            data: {data : json.stringify(value)},            success: function (data) {                     alert('success');                 },            error: error: function (result){                   alert('error');                 }            }); 

and here controller action method

     [httppost]      public actionresult  actionmethod(string value)      {          // value           } 

all i'm getting error alert message , js runtime error along null value value parameter. can 1 me in scenario. in advance.

try

$.ajax({            type: "post",            url: '@ url.action("actionmethod", "home")',            contenttype: 'application/json; charset=utf-8',            datatype: "json",            data: json.stringify({data: value}),            success: function (data) {                     alert('success');                 },            error: error: function (result){                   alert('error');                 }            });    

or

$.ajax({            type: "post",            url: '@ url.action("actionmethod", "home")',            contenttype: 'application/json; charset=utf-8',            datatype: "json",            data: value,            success: function (data) {                     alert('success');                 },            error: error: function (result){                   alert('error');                 }            }); 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -