I'm trying to implement ServerSide Processing using ASP.net MVC but the problem is when I load my project only the Index endpoint of my controller is getting hits and the path that I specified for loading data not reachable by my project so nothing loaded in my data table.
:
created code by Sitefinity does not contain Route.config so I could not check the path of controller functions but as I know the path of any controller will become like this "/Controlleername/functionname"
Controller:
[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>
}
Model:
public class TestModel
{
public string name { get; set; }
public string lastname { get; set; }
}
Update:
and when I use custom Route by Annotation also not working and I think the reason related to this but the problem is I'm working on Visual studio IIS and also localhost I believe this causes by Sitefinity but I don't know how to work around it
question from:
https://stackoverflow.com/questions/66054100/asp-net-mvc-controller-endpoint-not-reachable 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…