繁体   English   中英

AngularJs将url作为参数传递

[英]AngularJs passing url as parameter

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

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

如何在url中将url作为参数传递?

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

    });

在大多数语言中声明斜杠时,都需要转义它们。

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

像这样编码您的ListPath

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM