Link to home
Start Free TrialLog in
Avatar of RBS
RBS

asked on

How to create and go to MVC endpoint with Javascript

Hi:

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:

http://localhost:44328/Admin/ManageUsers/UserDetails/?username=jsmith

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:
http://localhost:44328/Admin/ManageUsers/UserDetails/%3Fusername=jsmith

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..

RBS
ASKER CERTIFIED SOLUTION
Avatar of Najam Uddin
Najam Uddin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of louisfr
louisfr

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.