Razor PartialView 内で実行されているいくつかの (動的に割り当てられた数の) 剣道グリッドがあります。グリッドは、MVC コントローラーから AJAX を介してデータを要求することを目的としています。コントローラーは読み取り要求を受信し、要求は正常であり、コントローラーは JSON を介してネットワーク経由でデータを返します (Fiddler を介して検証されます)。残念ながら、グリッドにはデータが表示されません。私はこれが初めてで、どこから始めればよいか途方に暮れています。私が知る限り、コードはこのシナリオの剣道の例と一致しています。どちらも問題なくアプリの他の部分で使用されるため、データやモデルの問題ではありません。
コントローラー:
public class MemberController : Controller
{
private MemberContext db = new MemberContext();
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Grid_Member_Read([DataSourceRequest] DataSourceRequest request,
int club_id)
{
var results = from r in db.Members where r.MemberClub.Id == club_id select r;
return Json(results.ToDataSourceResult(request));
}
}
パーシャルビュー:
@(Html.Kendo().Grid<RegistrationManagement.Models.Member>()
.Name("MembersGrid")
.Columns(columns =>
{
columns.Bound(p => p.LastName);
columns.Bound(p => p.FirstName);
columns.ForeignKey(p => p.MemberStatusID, (System.Collections.IEnumerable)ViewData["status"], "Value", "Text");
columns.Bound(p => p.RegistrationYear);
columns.Bound(p => p.StreetAddress1);
columns.Bound(p => p.StreetAddress2);
columns.Bound(p => p.State);
columns.Bound(p => p.ZipCode);
columns.Bound(p => p.Email);
columns.Bound(p => p.PhoneNumber);
columns.Command(command => { command.Custom("Edit2").Click("CustomEdit"); command.Edit(); command.Destroy(); }).Width(160);
})
.ToolBar(toolbar => toolbar.Create())
.Editable()
.Groupable()
.Pageable()
.Sortable()
.Scrollable()
.Filterable()
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.Batch(true)
.ServerOperation(false)
.Events(events => events.Error("error_handler"))
.Model(model =>
{
model.Id(p => p.Id);
model.Field(p => p.MemberStatus).Editable(false);
})
.Read(read => read
.Action("Grid_Member_Read", "Member", new { club_id = @ViewBag.ClubID })
)
.Create(create => create.Action("Grid_Member_Create", "Member", new { ClubID = @ViewBag.ClubID }))
.Update(update => update.Action("Grid_Member_Update", "Member"))
.Destroy(destroy => destroy.Action("Grid_Member_Destroy", "Member"))
)
)
function error_handler(e) {
if (e.errors) {
var message = "Errors:\n";
$.each(e.errors, function (key, value) {
if ('errors' in value) {
$.each(value.errors, function () {
message += this + "\n";
});
}
});
alert(message);
}
}
function CustomEdit(e) {
e.preventDefault();
var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
}
フィドラー データ:
グリッド 1 の読み取り要求に対するコントローラーの応答:
{"Data":[{"MemberClub":{"ClubRegion":{"Id":0,"Code":"TE","Name":"Test"},"ClubStatus": {"Id":0,"Name":"Unknown"},"RelationshipManager":{},"Id":1,"ClubName":"B Club","RegistrationYear":2000,"StreetAddress1":"street","StreetAddress2":"a","City":"city","State":"state","ZipCode":11111,"PhoneNumber":"555-1212","Email":"a@a.com","URL":"www.w.w."},"MemberStatus":{"Id":2,"Name":"Active"},"Id":1,"MemberClubID":1,"MemberStatusID":2,"MembershipNumberRoot":1,"LastName":"last","FirstName":"Edited","StreetAddress1":"street","StreetAddress2":"a","City":"city","State":"state","ZipCode":"11111","PhoneNumber":"555-1212","Email":"a@a.com","RegistrationYear":2000},{"MemberClub":{"ClubRegion":{"Id":0,"Code":"TE","Name":"Test"},"ClubStatus":{"Id":0,"Name":"Unknown"},"RelationshipManager":{},"Id":1,"ClubName":"B Club","RegistrationYear":2000,"StreetAddress1":"street","StreetAddress2":"a","City":"city","State":"state","ZipCode":11111,"PhoneNumber":"555-1212","Email":"a@a.com","URL":"www.w.w."},"MemberStatus":{"Id":10,"Name":"New"},"Id":10,"MemberClubID":1,"MemberStatusID":10,"MembershipNumberRoot":null,"LastName":"1","FirstName":"1","StreetAddress1":"1","StreetAddress2":"1","City":null,"State":"1","ZipCode":"1","PhoneNumber":"1","Email":"1","RegistrationYear":1},{"MemberClub":{"ClubRegion":{"Id":0,"Code":"TE","Name":"Test"},"ClubStatus":{"Id":0,"Name":"Unknown"},"RelationshipManager":{},"Id":1,"ClubName":"B Club","RegistrationYear":2000,"StreetAddress1":"street","StreetAddress2":"a","City":"city","State":"state","ZipCode":11111,"PhoneNumber":"555-1212","Email":"a@a.com","URL":"www.w.w."},"MemberStatus":{"Id":10,"Name":"New"},"Id":11,"MemberClubID":1,"MemberStatusID":10,"MembershipNumberRoot":null,"LastName":"2","FirstName":"2","StreetAddress1":"2","StreetAddress2":"2","City":null,"State":"2","ZipCode":"2","PhoneNumber":"2","Email":"2","RegistrationYear":2}],"Total":3,"AggregateResults":null,"Errors":null}
グリッド 2 の読み取り要求に対するコントローラーの応答:
{"Data":[{"MemberClub":{"RelationshipManager":{},"Id":2,"ClubName":"Test Club","RegistrationYear":2000,"StreetAddress1":"street","StreetAddress2":"a","City":"city","State":"state","ZipCode":11111,"PhoneNumber":"555-1212","Email":"a@a.com","URL":"www.w.w.","ClubRegion":{"Id":0,"Code":"TE","Name":"Test"},"ClubStatus":{"Id":0,"Name":"Unknown"}},"MemberStatus":{"Id":10,"Name":"New"},"Id":13,"MemberClubID":2,"MemberStatusID":10,"MembershipNumberRoot":2,"LastName":"Dude","FirstName":"Random","StreetAddress1":"street","StreetAddress2":"a","City":"City","State":"State","ZipCode":"11111","PhoneNumber":"555-1212","Email":"b@b.com","RegistrationYear":2012}],"Total":1,"AggregateResults":null,"Errors":null}
グリッド 3 への対応:
{"データ":[],"合計":0,"AggregateResults":null,"エラー":null}
(どちらが正しい)
複数のグリッドの表示を開始する前は、コントローラーから渡されたモデルを使用してデータを格納する単一のグリッドがありました。それは完璧に機能しました。次に、動的グリッドの作成を追加し (3 つのグリッドはすべて渡されたモデルを使用)、要求された最後のモデル データをすべて表示したので、AJAX アプローチから始めました。
この質問はまったくだまされているわけではありません。非常によく似た質問が以前に尋ねられましたが、コントローラーの読み取り関数 (正しく入力されている) に追加の値を渡していないものはありません。私が知る限り、これらの質問と成功しない剣道場。
これは根本的に基本的なものでなければなりません。何か案は?
ありがとう!