locked
MVC5 with JQUARY datatable RRS feed

  • Question

  • User1694748171 posted

    I have some issue in datatable, for both edit and details bottom its work fine with my local host, but when I published it to test server I got error that can't find resource. 

    I know the issue is href="/Assessment/Edit/' that is not working on server but is working on local host. I tried to used '@Url.Action("getAssessment", "Assessment")' instead but is not working for both. any idea ?

    this is my view 

    <!DOCTYPE html>
    <html lang="en">
    @using PagedList.Mvc
    @model PagedList.IPagedList<BoatSafetyExam.ViewModels.AssessmentViewModel>
    
    @{
        ViewBag.Title = "Index";
        Layout = "~/Views/Shared/_MasterLayout2.cshtml";
    }
    <script src="~/Scripts/jquery.min.js"></script>
    <script src="~/Scripts/bootstrap.bundle.js"></script>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
        <meta name="description" content="">
        <meta name="author" content="">
        <title> </title>
    
        <!-- Bootstrap core CSS -->
        <link href="~/Content/bootstrap.min.css" rel="stylesheet" />
    
        <!-- Custom styles for this template -->
        <link href="~/Content/simple-sidebar.css" rel="stylesheet" />
        <link href="//cdn.datatables.net/1.10.9/css/jquery.dataTables.min.css" rel="stylesheet" />
    
        <script src="//cdn.datatables.net/1.10.9/js/jquery.dataTables.min.js"></script>
    
    </head>
    
    <body>
        <div class="active">
            @Html.Partial("_NavBar")
        </div>
        <div class="d-flex " id="wrapper">
    
            <!-- Sidebar -->
            @Html.Partial("SidemenuBar")
    
            <!-- /#sidebar-wrapper -->
            <!-- Page Content -->
            <div id="page-content-wrapper">
    
                <h4 class="indent1"> Assessment Management </h4>
                <div class="col-md-8">
                    @Html.ActionLink("Add new Assessment", "Create", "Assessment", new { @class = "btn btn-primary" })
                </div>
                <br />
               
                <table class="table table-striped    table-bordered dt-responsive " id="questionlst" cellpadding="0" border="1" style="border-collapse:collapse">
                    <thead>
                        <tr>
                            <th>AssessmentStandard Name</th>
                            <th>Assessment  Name</th>
                            <th> </th>
                            <th> </th>
                           
                        </tr>
                    </thead>
                    <tbody></tbody>
                </table>
            </div>
        </div>
        <!-- /#page-content-wrapper -->
        <!-- /#wrapper -->
        <!-- Bootstrap core JavaScript -->
        <!-- Menu Toggle Script -->
        <script>
            $("#menu-toggle").click(function (e) {
                e.preventDefault();
                $("#wrapper").toggleClass("toggled");
            });
        </script>
    
    </body>
    
    </html>
    
    <script type="text/javascript">
        $(function () {
            $.ajax({
                type: "GET",
               // url: "/Assessment/getAssessment",
                url: '@Url.Action("getAssessment", "Assessment")',
                data: '{}',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: OnSuccess,
                failure: function (response) {
                    alert(response.d);
                },
                error: function (response) {
                    alert(response.d);
                }
            });
            
        });
        function OnSuccess(response) {
            $("#questionlst").DataTable(
                {
                    bLengthChange: true,
                    lengthMenu: [[5, 10, -1, 15], [5, 10, 15, "All"]],
                    bFilter: true,
                    type: "POST",
                    bSort: true,
                    bPaginate: true,
                    data: response,
                    "columnDefs":
                        [{
                            "targets": [0],
                            "visible": true,
                            "searchable": true
                        }],
                    columns: [
                        { 'data': 'AssessmentStandardName' },
                        { 'data': 'AssessmentName' },
    
                        {
                           // "render": function (data, type, full, meta) { return '<a class="btn btn-info" href="/Assessment/Edit/'+ full.AssessmentId + '">Edit</a>'; }
                            "render": function (data, type, full, meta) { return '<a class="btn btn-info" href="/Assessment/Edit/' + full.AssessmentId + '">Edit</a>'; }
                        },
    
                        {
                            "render": function (data, type, full, meta) { return '<a class="btn btn-info" href="/Assessment/Details/' + full.AssessmentId + '">Details</a>'; }
                        },
                        
    
                    ]
                   
                });
        };
    </script>
    
    

    on server when I click on edit or details bottom I got the error 

    404 - File or directory not found.

    The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable.

    Friday, September 18, 2020 7:28 PM

Answers

  • User1686398519 posted

    Hi luay20032003, 

    You can try this way of writing.

    return '<a class="btn btn-info" href="@Url.Action("Details","Assessment")/' + full.AssessmentId + '">Details</a>';
    public ActionResult Details(string AssessmentId)
    {
        return View();
    }

    Best Regards,

    YihuiSun

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 21, 2020 10:04 AM

All replies

  • User1686398519 posted

    Hi luay20032003, 

    You can try this way of writing.

    return '<a class="btn btn-info" href="@Url.Action("Details","Assessment")/' + full.AssessmentId + '">Details</a>';
    public ActionResult Details(string AssessmentId)
    {
        return View();
    }

    Best Regards,

    YihuiSun

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 21, 2020 10:04 AM
  • User1694748171 posted

    That's What I did, but thank you so much for your help.

    Monday, September 21, 2020 12:18 PM