JavaScript Datatables ajax 404 ошибка, когда я добавил еще один столбец - PullRequest
0 голосов
/ 07 декабря 2018

У меня есть приложение ASP.NET MVC, которое использует расширение JavaScript Datatables.Таблица имеет 7 столбцов.

Когда я добавляю еще один столбец в таблицу, возникает ошибка ajax 404.

Я попытаюсь объяснить ошибку своими кодами;

DbModel.cs

public class City
{
    public int CityId { get; set; }
    public string CityName { get; set; }
    public string PlateNumber { get; set; }
}

public class State
{
    public City City { get; set; }
    public int StateId { get; set; }
    public string StateName { get; set; }
    public string OrderNumber { get; set; }
}

public class Site
{
    public State State { get; set; }
    public int SiteId { get; set; }
    public string AboneNo { get; set; }
    public string SiteName { get; set; }
    public string Address { get; set; }
    public int BoilerCount { get; set; }
    public int BlockCount { get; set; }
    public string Abc { get; set; }
    public DateTime CreatedDate { get; set; }
}

SiteController.cs

public ActionResult Index()
{
    return View();
}

public JsonResult GetSites()
{
     DbManager dbManager = new DbManager();
     DataTable dt = dbManager.GetSites();
     List<Site> allSites = new List<Site>();
     foreach (DataRow row in dt.Rows)
     {
         City city = new City
         {
             CityId = Convert.ToInt32(row["il_id"]),
             CityName = row["il_adi"].ToString(),
             PlateNumber = row["plaka"].ToString()
         };
         State state = new State
         {
             City = city,
             StateId = Convert.ToInt32(row["ilce_id"]),
             StateName = row["ilce_adi"].ToString(),
              OrderNumber = row["sira_no"].ToString()
         };
         Site site = new Site
         {
             State = state,
             AboneNo = row["abone_no"].ToString(),
             Abc = row["aktif"].ToString(),
             Address = row["adres"].ToString(),
             BlockCount = Convert.ToInt32(row["blok_sayisi"]),
             BoilerCount = Convert.ToInt32(row["kazan_sayisi"]),
             SiteId = Convert.ToInt32(row["site_id"]),
             SiteName = row["site_adi"].ToString()
         };
         allSites.Add(site);
     }

     return Json(new { data = allSites }, JsonRequestBehavior.AllowGet);
 }

Index.cshtml

<table class="table table-striped- table-bordered table-hover table-checkable" id="tbl_site">
    <thead>
        <tr>
            <th>SİTE ID</th>
            <th>ABONE NO</th>
            <th>İL</th>
            <th>İLÇE</th>
            <th>SİTE ADI</th>
            <th>ADRES</th>
            <th>KAZAN SAYISI</th>
            <th>BLOK SAYISI</th>
            <th>Abc</th>
        </tr>
    </thead>
</table>
@section scripts{
    @Scripts.Render("~/res/js/datatables.bundle.js")
    <script>
        $('#tbl_site').DataTable({
            ajax: {
                url: "Site/GetSites",
                type: "GET",
                dataType: "json",
                error: function (error) {
                    alert(error);
                }
            },
            processing: true,
            serverSide: true,
            columns: [
                { data: 'SiteId', autoWidth: true },
                { data: 'AboneNo', autoWidth: true },
                { data: 'State.City.CityName', autoWidth: true },
                { data: 'State.StateName', autoWidth: true },
                { data: 'SiteName', autoWidth: true },
                { data: 'Address', autoWidth: true },
                { data: 'BoilerCount', autoWidth: true },
                { data: 'BlockCount', autoWidth: true },
                //{ data: 'Abc', autoWidth: true }
            ]
        });
    </script>
}

Произошла ошибка ajax 404, когда я раскомментировал закомментированную строку в Index.cshtml

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...