Файл cshtml: (home.cshtml)
@using Kendo.Mvc.UI;
<!DOCTYPE html>
<html>
<head>
<title>Welcome to Kendo UI!</title>
<!-- Common Kendo UI CSS for web widgets and widgets for data visualization. -->
<link href="~/Kendo/styles/kendo.common.min.css" rel="stylesheet" />
<!-- (Optional) RTL CSS for Kendo UI widgets for the web. Include only in right-to-left applications. -->
<link href="~/Kendo/styles/kendo.rtl.min.css" rel="stylesheet" type="text/css" />
<!-- Default Kendo UI theme CSS for web widgets and widgets for data visualization. -->
<link href="~/Kendo/styles/kendo.default.min.css" rel="stylesheet" />
<!-- (Optional) Kendo UI Hybrid CSS. Include only if you will use the mobile devices features. -->
<link href="~/Kendo/styles/kendo.default.mobile.min.css" rel="stylesheet" type="text/css" />
<!-- jQuery JavaScript -->
<script src="~/Kendo/js/jquery.min.js"></script>
<!-- Kendo UI combined JavaScript -->
<script src="~/Kendo/js/kendo.all.min.js"></script>
</head>
<body>
@(Html.Kendo().Grid<MiCustomerSentiment.UserProfile>()
.Name("divSearchResult")
.DataSource(dataSource => dataSource // Configure the grid data source
.Ajax() // Specify that ajax binding is used
.Read(read => read.Action("Products_Read", "Home"))
)
.Columns(columns =>
{
columns.Bound(user => user.FirstName);
columns.Bound(user => user.LastName);
columns.Bound(user => user.EmployeeId);
columns.Bound(user => user.UserName);
})
.Pageable() // Enable paging
.Sortable() // Enable sorting
)
</body>
</html>
Метод действия Backend в контроллере:
using Kendo.Mvc.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MiCustomerSentiment.Models;
using Kendo.Mvc.Extensions;
namespace MiCustomerSentiment.Controllers
{
public class HomeController : Controller
{
public ActionResult Home()
{
return View();
}
[HttpGet]
public ActionResult Products_Read([DataSourceRequest]DataSourceRequest request)
{
using (var _db = new SampleData())
{
IQueryable<UserProfile> unitslist = _db.UserProfiles;
DataSourceResult result = unitslist.ToDataSourceResult(request);
return Json(result,JsonRequestBehavior.AllowGet);
}
}
}
}
Модель: (UserProfile.cs)
namespace MiCustomerSentiment
{
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.Spatial;
[Table("support.UserProfile")]
public class UserProfile
{
[Key]
public int UserId { get; set; }
[Required(ErrorMessage = "First Name is required")]
[StringLength(100)]
public string FirstName { get; set; }
[Required(ErrorMessage = "Last Name is required")]
[StringLength(100)]
public string LastName { get; set; }
[Required(ErrorMessage = "Employee Id is required")]
[StringLength(100)]
public string EmployeeId { get; set; }
[Required(ErrorMessage = "UserName is required")]
[StringLength(100)]
public string UserName { get; set; }
[Required(ErrorMessage = "Password is required")]
[StringLength(50)]
public string Password { get; set; }
public bool? IsActive { get; set; }
public DateTime ModifiedDate { get; set; }
public string ModifiedBy { get; set; }
}
}
Спасибо за помощь!
Пробовал со всеми ссылками, у которых были похожие проблемы. Но не смог получить ответ на мою проблему.
попытался добавить JsonBehavior.Allowget в методы действия контроллера.
Попытка добавления глагола [httpget].
Ожидаемый результат: данные должны быть показаны в сетке.