ajax - Json post to MVC controller with Parameters -


can't seems figure out why not working. can't parameters post mvc controller method:

@{     viewbag.title = "index"; }  <h2>index</h2>  <input id="button1" type="button" value="button" onclick="callmethodone()" />  <div id="result"></div>  <script>      function callmethodone() {          var detailsurl = '/testdrive/methodone';          var request = {             'parameterone': "test one",             'parametertwo': "test two"         };          $.ajax({             url: detailsurl,             contenttype: "applicaton/json",             type: "post",             data: json.stringify(request),             datatype: "json",             success: successfunc,             error: errorfunc         });          function successfunc(response, status) {             //alert(data + " " + status);             $("#result").text(response.result);         }          function errorfunc(xhr, status) {             alert("error");         }      }  </script> 

and controller method this:

    [httppost]     [allowanonymous]     public actionresult methodone(string parameterone, string parametertwo)     {         return view();     } 

parameterone or parametertwo not have values in them.

update:

enter image description here

you should create class parameters, try this:

[serializable] public class your_class_name {   public string parameterone {get; set;}   public string parametertwo {get; set;} } 

at controller:

[httppost] [allowanonymous] public actionresult methodone(your_class_name parameters) {   // badass code here } 

hope works =d


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -