Kurkula
Kurkula

Reputation: 6762

AngularJs passing url as parameter

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);

    });

Upvotes: 0

Views: 309

Answers (2)

Divyesh Kanzariya
Divyesh Kanzariya

Reputation: 3789

just encode your ListPath var like this

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

Upvotes: 1

Icycool
Icycool

Reputation: 7179

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

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

Upvotes: 1

Related Questions