AngularJs将url作为参数传递

时间:2016-11-24 05:11:08

标签: javascript angularjs

我试图通过angularjs将路径url作为参数传递给我的asp.net mvc控制器方法。 当我调试时,我看到代码上的Path参数缺少斜杠。

而不是“D:\ MyDir \ List.txt”,它显示“D:MyDirList.txt”

如何将URL作为参数传递给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 个答案:

答案 0 :(得分:1)

当你用大多数语言声明它们时,你需要转义斜杠。

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

答案 1 :(得分:1)

只需像这样编码你的ListPath var

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