Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
278 views
in Technique[技术] by (71.8m points)

Asp.net MVC Controller endpoint not reachable

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Did you add your widget to a page that has a url of /Test ?

Only then you can expect that /test/loadData will be reached


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...