用这个苦苦挣扎。我将控制器的绝对URL传递给View,并试图检索jquery中的URL,将它传递给Ajax调用。该URL没有正确构建。任何帮助如何以正确的方式检索它?从jQuery中的MVC ViewData中检索URL
我试了@ Html.Raw在这里。但没有运气!
MVC控制器
public IActionResult Something()
{
var baseDirPath= System.AppDomain.CurrentDomain.BaseDirectory;
var fileLocation = Path.Combine(baseDirPath, "wwwroot", "myDir",
"test.docx");
ViewData["Path"] = fileLocation;
return View();
}
MVC视图
<script type="text/javascript">
$(document).ready(function() {
//Cannotretrieve the path here from the viewdata
var path = "@Html.Raw(ViewData["Path"])";
console.log(documentPath);
var kkk= $("#div");
kkk.kendoWindow({
open: function (e) {
$.ajax({
url: documentPath,
async: true,
success: function (msg) {
//success
},
});
}
}).data("kendoWindow").center().open();
});
</script>
可以显示示例路径,这是什么路? –
更新的控制器代码 – aspnetbeginner245
您无法使用绝对路径访问该文件,您需要使用相对路径 –