2016-11-24 118 views
0

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

等代替 “d:\ MYDIR \ LIST.TXT” 它显示 “d:MyDirList.txt”

我如何能够通过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); 

    }); 
+0

我认为在发送之前,你应该使用编码encodeURIComponent方法() –

+0

这个路径,请看看例子http://stackoverflow.com/questions/16630471/how-can-i-invoke-encodeuricomponent-from-angularjs-template –

回答

1

当你用大多数语言声明它们时,你需要避开你的斜杠。

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

+0

但是当我们从文本框拉出路径时,我们无法得到这个\\。我们该如何处理? – Kurkula

+0

如果它从文本框传递,那么它已经正确处理,只是通过该变量将没事。 – Icycool

1

只是编码您ListPath变种这样

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