0

I am trying to pass a path url as parameter to my asp.net mvc controller method through angularjs. When I debug I see that Path parameter on code is missing slashes in it.

Like instead of "D:\MyDir\List.txt" it show "D:MyDirList.txt"

how can I pass url as parameter in angular?

 public JsonResult GetData(string Path)
        {          

            var details = GetResult(Path);
            return Json(details, JsonRequestBehavior.AllowGet);
        }

var ListPath = "D:\MyDir\List.txt";

$http.get("/Home/GetData",
    { params: { "Path": ListPath })
    .then(function (response) {
        console.log(response);

    });
2
  • I think before sending it you should encode this path using encodeURIComponent() Commented Nov 24, 2016 at 5:22
  • Please have a look at example stackoverflow.com/questions/16630471/… Commented Nov 24, 2016 at 5:23

2 Answers 2

1

You need to escape your slashes when you declare them in most languages.

var ListPath = "D:\\MyDir\\List.txt";

Sign up to request clarification or add additional context in comments.

2 Comments

but we cannot get this \\ when we pull path from textbox. how do we handle this?
if it is passing from textbox then it is already handled correctly, just pass that variable would be fine.
1

just encode your ListPath var like this

var ListPath = window.encodeURIComponent("D:\MyDir\List.txt");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.