[英]Problem with Telerik Grid and MVC3
我對MVC3和Telerik Grid有點問題。 我有以下模型:
public class Country
{
[Key]
public int CountryID { get; set; }
public string CountryName { get; set; }
public string CountryShortName { get; set; }
//
// Example
public ICollection<City> Citys { get; set; }
}
和我的City
模型:
public class City
{
[Key]
public int CityID { get; set; }
public string CityName { get; set; }
//
// ....
public virtual Country Country { get; set; }
}
我使用MVCScaffolding
(...,使用存儲庫),並且有:
public class CountryRepository : ICountryRepository
{
ProjektContext context = new ProjektContext();
public IQueryable<Country> All
{
get { return context.Country; }
}
public IQueryable<Country> AllIncluding(params Expression<Func<Country, object>>[] includeProperties)
{
IQueryable<Country> query = context.Country;
foreach (var includeProperty in includeProperties) {
query = query.Include(includeProperty);
}
return query;
}
}
//... and more more more :)
public interface ICountryRepository
{
IQueryable<Country> All { get; }
IQueryable<Country> AllIncluding(params Expression<Func<Country, object>>[] includeProperties);
// .. more more ....
}
和我的控制器和視圖:
public class CountryController : Controller
{
private readonly ICountryRepository countryRepository;
// If you are using Dependency Injection, you can delete the following constructor
public CountryController() : this(new CountryRepository()) {}
public CountryController(ICountryRepository countryRepository)
{
this.countryRepository = countryRepository;
}
//
// GET: /Country/
public ViewResult Index()
{
return View(countryRepository.AllIncluding(country => country.Citys));
}
[GridAction]
public ActionResult _AjaxIndex()
{
return View(new GridModel<Country>
{
Data = countryRepository.AllIncluding(country => country.Citys)
});
}
}
我的Index.cshtml:
@model IEnumerable<Test.Models.Country>
@{
ViewBag.Title = "Index";
}
@(Html.TelCountryerik().Grid(Model)
.DataBinding(dataBinding => dataBinding.Ajax().Select("_AjaxIndex", "Country"))
.Name("Country")
.Columns(columns =>
{
columns.Bound(c => c.CountryName);
columns.Bound(c => c.CountryShortName);
})
.Sortable()
.Pageable()
.Groupable()
.Filterable()
)
City
值。 我嘗試遵循一個示例,但沒有得到正確的結果。 當我嘗試對過濾器網格排序時會發生問題(當然沒有詳細信息)。 我遇到了安全性錯誤,但是當我在下面的代碼中更改_AjaxIndex
,一切都很好(當然,不能訪問城市)。
[GridAction] public ActionResult _AjaxIndex() { return View(new GridModel<Country> { Data = countryRepository.All }); }
誰能幫我解決我的問題?
我自己解決問題。 問題是Telerink Components中的錯誤(如果您使用NUGet下載)無法在jQuery 1.6+上正常工作。
這是指向'問題解析器:P'的鏈接jQuery 1.6+ Telerink + MVC FIX
我希望Telerink能夠很快更新NUGet上錯誤(舊)組件的版本。
這是示例-經過測試
@(Html.Telerik().ScriptRegistrar()
.jQuery(false)
.jQueryValidation(false)
.DefaultGroup(group => group
.Add("~/Scripts/jquery-1.6.4.js")
.Add("~/Scripts/jquery.validate.js")
.Add("~/Scripts/modernizr-2.0.6-development-only.js")
.Add("~/Scripts/2011.2.712/telerik.common.min.js")
.Add("~/Scripts/2011.2.712/telerik.textbox.min.js")
.Add("~/Scripts/2011.2.712/telerik.grid.min.js")
.Add("~/Scripts/2011.2.712/telerik.draganddrop.min.js")
.Add("~/Scripts/2011.2.712/telerik.grid.grouping.min.js")
.Add("~/Scripts/2011.2.712/telerik.grid.filtering.min.js")
.Add("~/Scripts/2011.2.712/telerik.grid.editing.min.js")
.Add("~/Scripts/2011.2.712/telerik.window.min.js")
.Combined(true)
.Compress(true))
.OnDocumentReady(
@<text>
prettyPrint();
</text>)
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.