How to create and go to MVC endpoint with Javascript


I have an MVC app in which I am doing a lookup in javascript and would like the program to take me to the following endpoint:


Open in new window

I have a have a javascript function that looks like this:

 window.SalesHub.SearchBox_Select = function(e) {
        var baseUrl = 'http://localhost:44328';
        var actionUrl = '/Admin/ManageUsers/UserDetails/\?username=';
        var userName = 'jsmith';
        window.location.pathname = baseUrl + actionUrl + userName ;

Open in new window

My problem is that this function takes me to:

Open in new window

and tells me that "A potentially dangerous Request.Path value was detected from the client"

I have tried escaping the '?' character but that does not seem to work.  Any assistance on how to make this function take me to the endpoint that I want to go to greatly appreciated..

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Najam UddinCommented:
try this
window.location.pathname= '@Url.Action("UserDetails", "ManageUsers", new{ area = "Admin", username ="jsmith"})'

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Set the href property instead.
The pathname starts after the hostname and port and ends before the querystring. It cannot contain a question mark. That's why it is escaped.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.