Passing dynamic javascript values using Url.action()

后端 未结 4 1448
滥情空心
滥情空心 2020-11-29 02:53

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

Something Like,

var firstname=\"abc\";
var username = \"abcd\";
location.href         


        
4条回答
  •  离开以前
    2020-11-29 03:13

    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:

    var firstname = "abc";
    var username = "abcd";
    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.

提交回复
热议问题