如何解决Asp.net MVC 控制器端点无法访问
我正在尝试使用 ASP.net MVC 实现服务器端处理,但问题是当我加载我的项目时,只有我的控制器的 Index 端点得到点击,并且我指定的用于加载我的项目无法访问的数据的路径我的数据表中没有加载任何内容。 : Sitefinity 创建的代码不包含 Route.config,所以我无法检查控制器函数的路径,但我知道任何控制器的路径都会变成这样的“/Controlleername/functionname”
控制器:
[ControllerToolBoxItem(Name = "Test",Title = "Test Page",SectionName = "MyCustom")]
public class TestController : Controller
{
// GET: Test
public ActionResult Index()
{
return View();
}
[HttpPost]
public JsonResult LoadData()// I put Breakpoint here and nothing reached
{
TestModel test = new TestModel();
test.name = "name1";
test.lastname = "lastnmae1";
test.name = "name2";
test.lastname = "lastnmae2";
return Json(test);
}
}
Index.cshtml:
@{
ViewBag.Title = "Index";
}
<div style="width:90%; margin:0 auto;">
<table id="myTable">
<thead>
<tr>
<th>name</th>
<th>lastname</th>
</tr>
</thead>
</table>
</div>
@* Load datatable css *@
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<link href="//cdn.datatables.net/1.10.23/css/jquery.dataTables.min.css" rel="stylesheet" />
@section Scripts{
@* Load DataTable js here *@
<script src="//cdn.datatables.net/1.10.23/js/jquery.dataTables.min.js"></script>
<script>
$(document).ready(function () {
$("#myTable").DataTable({
"processing": true,// for show progress bar
"serverSide": true,// for process server side
"filter": false,// this is for disable filter (search Box)
"orderMulti": false,// for disable multiple column at once
"ajax": {
"url": "/Test/LoadData","type": "POST","datatype": "json"
},"columns": [
{ "data": "name","name": "name","autoWidth": true },{ "data": "lastname","name": "lastname",]
});
});
</script>
}
型号:
public class TestModel
{
public string name { get; set; }
public string lastname { get; set; }
}
更新:
当我通过注释使用自定义路由时也不起作用,我认为原因与 this 有关,但问题是我正在使用 Visual Studio IIS 和 localhost 我相信这是由 Sitefinity 引起的,但我不知道如何解决它
解决方法
您是否将小部件添加到具有 /Test 网址的页面?
只有这样你才能期望达到/test/loadData
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。