老项目是asp.net web,现因为项目需要转为.net core,现版本是.net core 3.1, 在做相关老项目迁移时,后端代码写进了razor的cshtml文件AWebReadNetInfo,前端文件基本没有怎么改是html文件,放在wwwroot下,在用ajax传参时候,url找不到这个新建的cshtml文件,把AWebReadNetInfo放在wwwroot里和wwwroot外都试过了,都无法找到
问题相关代码,请勿粘贴截图
//AWebReadNetInfo.cshtml目前放在wwwroot路径下
$.ajax({
type: "post",
async: true, //同步执行
url: "/AWebReadNetInfo",
beforeSend: function (xhr) {
xhr.setRequestHeader("XSRF-TOKEN",
$('input:hidden[name="__RequestVerificationToken"]').val());
},
contentType: "application/json; charset=utf-8",
dataType: "json", //返回数据形式为json
success: function (result) {
alert("数据初始化成功!");
console.log(result)
},
error: function (errorMsg) {
alert("没有您想要的数据内容!");
}
});
运行结果及报错内容
报错:Failed to load resource: the server responded with a status of 404 ()
我的解答思路和尝试过的方法
我在想是不是绝对路径和相对路径的问题,但是其他文件href链接都能找到,唯独url这里不行。
参照这个链接https://www.jb51.net/article/133437.htm,也在框架中添加了关于XSRF-TOKEN的内容
我想要达到的结果
应该如何写这个url,它的后端文件应该放在哪里,期待能解答下疑问,感谢,好人一生平安!