Asp.net MVC控制器端点不可达



我试图使用ASP.net MVC实现服务器端处理,但问题是当我加载我的项目时,只有我的控制器的索引端点得到命中和我指定的加载数据的路径,我的项目无法到达,所以没有加载在我的数据表中。:Sitefinity创建的代码不包含Route。所以我不能检查控制器函数的路径,但我知道任何控制器的路径都会变成这样"/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", "autoWidth": true },

]
});
});
</script>
}

模型:

public class TestModel
{
public string name { get; set; }
public string lastname { get; set; }
}

:
当我使用自定义Route by Annotation时也不起作用我认为原因与此有关但问题是我正在使用Visual studio IIS和localhost我认为这是由Sitefinity引起的但我不知道如何解决

您是否将小部件添加到url为/Test的页面中?

只有这样你才能期望到达/test/loadData

最新更新