Reputation: 570
Hello guys i am developing MVC application, I want to call a action (with 2 parameter) when i click on some button and on the event handler of the button i do the following :
var url = '<%: Url.Action("SomeAction", "SomeConroller") %>'
$(location).attr('href', url, new { param1 : value1 , param2: value2 });
but this not working .. how can i pass parameters in this case ??? any help ???
Upvotes: 0
Views: 77
Reputation: 16974
You want to pass in your two parameters with the Url.Action method:
var url = '<%: Url.Action("SomeAction", "SomeConroller", new { param1 = value1, param2 = value2 }) %>'
Sorry, realised the parameter values may not be accessible in the method. You could add placeholders and replace them afterwards:
var url = '<%: Url.Action("SomeAction", "SomeConroller", new { param1 = "VAL1", param2 = "VAL2" }) %>';
url = url.replace("VAL1", encodeURIComponent(value1));
url = url.replace("VAL2", encodeURIComponent(value2));
Upvotes: 1
Reputation: 887413
You need to manually create the URL, like this:
url + "?Param1=" + encodeURIComponent(value1)
+ "&Param2=" + encodeURIComponent(value2)
Upvotes: 0