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

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...