Url.Action in jquery ajax: Second parameter not passed -


i trying pass 2 parameters in url.action function jquery ajax, , first parameter passed. both parameters show correctly in ajax function when debug. values passed in data passed correctly.

what doing wrong?

here code view:

<script type="text/javascript">      $(function () {         $("#sendform").click(function () {             //they both show correctly in console             console.log('@viewdata["recordurl"]');             console.log('@viewdata["title"]');             $.ajax({                 url: '@url.action("sendemail", "search", new { title = viewdata["title"], recordurl = viewdata["recordurl"] })',                 type: "post",                 data: {                     //placed these here don't have intersperse javascript razor code in url.action                     recepient: $("#recepient").val(),                     message: $("#message").val()                 },                 success: function (result) {                     $(".emailform").hide();                     $(".results").text(result);                      window.settimeout(closeemailpopup, 3500);                 }             });         });     }); </script> 

and controller:

[httppost] public virtual actionresult sendemail(string title, string recordurl, string recepient, string message = "") {     // title correct value, recordurl null.      // if switch order in url.action in view,     // recordurl has correct value, , title null        //recepient , message have correct value } 

i guess problem final url string. try wrapping in html.raw prevent escaping & symbols:

... url: '@html.raw(url.action("sendemail", "search", new { title = viewdata["title"], recordurl = viewdata["recordurl"] }))', ... 

taken answer.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -