Sunday, May 19, 2024
Homepage · c#
 Popular · Latest · Hot · Upcoming
125
rated 0 times [  126] [ 1]  / answers: 1 / hits: 170286  / 11 Years ago, wed, february 27, 2013, 12:00:00

Could anyone please tell how to pass dynamic values using Url.action().



Something Like,



var firstname=abc;
var username = abcd;
location.href = '@Html.Raw(@Url.Action(Display, Customer, new { uname = firstname ,name = username}))';


firstname, username is not getting reffered inside the Url.action() method.



How to pass these dynamic values using Url.action()?


More From » c#

 Answers
10

The @Url.Action() method is proccess on the server-side, so you cannot pass a client-side value to this function as a parameter. You can concat the client-side variables with the server-side url generated by this method, which is a string on the output. Try something like this:


let firstName = "John";
let userName = "Smith";
location.href = '@Url.Action("Display", "Customer")?uname=' + firstName + '&name=' + userName ;

The @Url.Action("Display", "Customer") is processed on the server-side and the rest of the string is processed on the client-side, concatenating the result of the server-side method with the client-side.


[#79965] Tuesday, February 26, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
harleyterryp

Total Points: 290
Total Questions: 92
Total Answers: 95

Location: Montenegro
Member since Sun, May 7, 2023
1 Year ago
;