1

グリッドで ajax バインディング データをテストしようとしています。データ列が数値 (int、double、float など) の場合、エラーまたはディクショナリとモデルのデータ型の非互換性が発生します: ディクショナリに渡されたモデル項目の型は 'System.Int32' ですが、このディクショナリにはモデル項目が必要ですタイプ「System.String」の。

これはバージョン 1.319 で発生します。1.315 の初期のバージョンでは問題なく動作していました。

コントローラ:

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

public ActionResult AjaxRead([DataSourceRequest] DataSourceRequest request)
{
var persons = new List<Person>()
{
new Person() {Id = 1, Name = "Jack", Age = 13},
new Person() {Id = 2, Name = "Riley", Age = 45},
new Person() {Id = 3, Name = "William", Age = 34},
new Person() {Id = 4, Name = "Oliver", Age = 66},
new Person() {Id = 5, Name = "Lachlan", Age = 35},
new Person() {Id = 6, Name = "Thomas", Age = 53},
new Person() {Id = 7, Name = "Lachlan", Age = 24},
new Person() {Id = 8, Name = "John", Age = 54},
new Person() {Id = 9, Name = "Alex", Age = 19},
new Person() {Id = 10, Name = "Victor", Age = 39},
new Person() {Id = 11, Name = "Joshua", Age = 33}
};
return Json(persons.ToDataSourceResult(request));
}
}

public class Person
{
[ScaffoldColumn(false)]
public int Id { get; set; }
public string Name { get; set; }
public int Age { get; set; }
}

意見:

@(Html.Kendo().Grid<Kendo.Mvc.Examples.Controllers.Person>()    
    .Name("Grid")
    .Columns(columns => {
        columns.Bound(p => p.Id).Groupable(false);
        columns.Bound(p => p.Name);
        columns.Bound(p => p.Age);
    })
    .Pageable()
    .Sortable()
    .Filterable()
    .Groupable()
    .Editable(editable => editable.Mode(GridEditMode.PopUp))
    .DataSource(dataSource => dataSource
        .Ajax()
        .PageSize(8)
        .Model(model => model.Id(p => p.Id))
        .Read("AjaxRead", "Grid")
    )
)

次のようにコードを変更すると

public class Person
{
    [ScaffoldColumn(false)]
    public int Id { get; set; }
    public string Name { get; set; }
    [DataType("Integer")]
    public int Age { get; set; }
}

エラーは発生しません。

アプリケーションのすべてのクラスのすべての数値フィールドに属性を設定したくありません。特に、以前のバージョンでは問題なく機能していました。

しかし、そうでない場合は、私が間違っていることを教えてください。

ありがとう、ヴラド

4

0 に答える 0