【发布时间】:2017-08-23 04:00:42
【问题描述】:
我有一个带有侧边栏的视图,其中包含文件列表,部分视图包含一个文本区域。我想在用户单击文件后显示文件的内容(通过刷新部分视图)。这是我正在使用的脚本:
<script>
$(document).ready(function () {
$('.filelist').on('click', function (e) {
var filePath = $(this).attr('value'); //value is attribute set in Html
$('#partial').load('DevelopmentPartial', { path1: filePath });
});
});
</script>
它一直正常工作,直到昨天,我在重定向到此视图时开始收到此错误,但如果直接访问它则不会:
请求的内容似乎是脚本,不会被 静态文件处理程序
我能够摆脱错误,但现在除非我访问 直接查看,但如果我从另一个操作方法重定向到它,它不会!
这是我的控制器:
StudentsCodes modelSC;
public DevelopmentController()
{
m4 = new MicroG4();
modelSC = new StudentsCodes();
}
public ActionResult Index()
{
modelSC.Student = (Student)CurrentUser;
var user = UserManager.FindById(((Student)CurrentUser).InstructorID);
modelSC.Instructor =(Instructor) user;
//modelSC.path = "~/Content/" + CurrentUser.UserName + "/CompilerProject/src/Driver.java";
return View(modelSC);
}
public PartialViewResult DevelopmentPartial(string path1)
{
modelSC.Student = (Student)CurrentUser;
var user = UserManager.FindById(((Student)CurrentUser).InstructorID);
modelSC.Instructor = (Instructor)user;
modelSC.path = path1;
modelSC.code = "";
if (modelSC.path == null)
{
modelSC.code = "";
}
else
{
try
{
modelSC.code = System.IO.File.ReadAllText(Server.MapPath(modelSC.path));
}
catch (Exception e)
{
modelSC.code = "";
}
}
return PartialView(modelSC);
}
我做错了什么?
【问题讨论】:
-
你能不能把这个脚本放到主视图页面而不是局部视图中
-
这个脚本在主视图中,它调用局部视图。
-
猜你检查控制台窗口是为了给你一个关于发生了什么的提示!
-
其实这是我的第一个网站,一直在尝试,还不知道怎么排查问题。
标签: javascript razor asp.net-mvc-5