PDA

View Full Version : [CLOSED] MVC Grid - Server Databinding



adelaney
May 02, 2012, 7:52 PM
How can I bind a grid store to a model from the server? I had thought that something like this would work:


.Store(Sub(action)
action.Add(Html.X.Store().AutoLoad(True) _
.Model(Sub(mdl)
mdl.Add(Html.X().Model.Fields(Sub(fields)
fields.Add(Html.X.ModelField.Name("Name"))
fields.Add(Html.X.ModelField.Name("UKCode"))
fields.Add(Html.X.ModelField.Name("DateSentToRI").Type(ModelFieldType.Date).DateFormat("M$"))
fields.Add(Html.X.ModelField.Name("DateSignedDocSentToRI").Type(ModelFieldType.Date).DateFormat("M$"))
fields.Add(Html.X.ModelField.Name("Code"))
fields.Add(Html.X.ModelField.Name("TrackDates").Type(ModelFieldType.Boolean))
fields.Add(Html.X.ModelField.Name("DateReceivedFromRI").Type(ModelFieldType.Date).DateFormat("M$"))
fields.Add(Html.X.ModelField.Name("NeverSigning").Type(ModelFieldType.Boolean))
End Sub))
End Sub) _
.PageSize(20).DataSource(Model))
End Sub)

(Model is a List(of CustomType)) However, this doesn't work. Can you tell me if this is possible, and if so how?

Daniil
May 02, 2012, 10:03 PM
Hi,

Well, it works on my side. Here is my test case.

Example View

@inherits System.Web.Mvc.WebViewPage<List<object>>

<!DOCTYPE html>

<html>
<head>
<title>Ext.NET Razor Example</title>
</head>
<body>
@Html.X().ResourceManager()

@(Html.X().GridPanel()
.AutoHeight(true)
.Store(store =>
store.Add(
Html.X().Store()
.Model(m =>
m.Add(Html.X().Model()
.Fields(f =>
{
f.Add(Html.X().ModelField().Name("test1"));
f.Add(Html.X().ModelField().Name("test2"));
f.Add(Html.X().ModelField().Name("test3"));
})
)
)
.DataSource(Model)
)
)
.ColumnModel(cm =>
{
cm.Add(Html.X().Column().DataIndex("test1").Text("Test 1"));
cm.Add(Html.X().Column().DataIndex("test2").Text("Test 2"));
cm.Add(Html.X().Column().DataIndex("test3").Text("Test 3"));
})
)
</body>
</html>

Example Controller Action

public ActionResult TestRazor()
{
return View(new List<object>()
{
new
{
test1 = "test11",
test2 = "test12",
test3 = "test13"
},
new
{
test1 = "test21",
test2 = "test22",
test3 = "test23"
}
});
}