2011-09-13 20 views
0

MVC3とTelerik Gridに少し問題があります。Telerik GridとMVC3の問題

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() 
) 
  1. 私はTelerikグリッド(マスタ/詳細グリッド)からCity値にアクセスすることができません。私は例に従おうとしますが、私は正しい結果を得ていません。
  2. フィルタのグリッドを並べ替えるときに問題が発生します(もちろん詳細はありません)。私はセキュリティのエラーがありますが、私が_AjaxIndexのコードをすべて変更しても問題ありません(もちろん、都市へのアクセスなし)。

    [GridAction] 
    public ActionResult _AjaxIndex() 
    { 
        return View(new GridModel<Country> 
        { 
         Data = countryRepository.All 
        }); 
    } 
    

誰もが私の問題で私を助けることができますか?

答えて

1

私自身で問題を解決します。 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>) 
)