[英]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.