Hi.
I’m new at MVC and I have a problem.
The problem is that a sub grid does not show any results.
Here is my view code:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<
LogReaderTest.Models.LogModel
>" %>
<
asp:Content
ID
=
"Content1"
ContentPlaceHolderID
=
"TitleContent"
runat
=
"server"
>
Index
</
asp:Content
>
<
asp:Content
ID
=
"Content2"
ContentPlaceHolderID
=
"MainContent"
runat
=
"server"
>
<
h2
>Index</
h2
>
<
div
class
=
"editor-label"
>
<% Html.BeginForm("Search", "Home", FormMethod.Post); %>
Start Date<
br
/>
<%=Html.TextBox("StartDate", ViewData["StartDate"], new { style = "width:80px" })%>
<
br
/>
<
br
/>
End Date<
br
/>
<%=Html.TextBox("EndDate", ViewData["EndDate"], new { style = "width:80px" })%>
<
br
/>
<
br
/>
<
input
type
=
"submit"
name
=
"submitButton"
value
=
"Search"
/>
<
br
/>
<
br
/>
<%if (Model != null) { %>
<%= Html.Telerik().Grid(Model.ToDataView)
.Name("Trades")
.Columns(columns =>
{
columns.Bound("Id").Title("Ticket").Width(80);
columns.Bound("DateTime").Width(170);
columns.Bound("Type").Width(230);
columns.Bound("Message");
})
.ClientEvents(events=> events.OnRowDataBound("trades_onRowDataBound"))
.DetailView(details => details.ClientTemplate(
Html.Telerik().Grid(Model.ToDataView)
.Name("Orders_<#= Id #>")
.Columns(columns =>
{
columns.Bound("Message");
})
.DataBinding(dataBinding => dataBinding.Ajax()
.Select("_Orders", "Home", new {
ticket = "<#= Id #>"}))
.Pageable()
.Sortable()
.ToHtmlString()
))
.DataBinding(dataBinding => dataBinding.Server().Select("_Trades", "Home"))
.Pageable(paging => paging.PageSize(60))
.Scrollable(scrolling => scrolling.Height(1200))
.Sortable()
%>
<% }
else if (Model == null)
{ %>
<% } %>
<
script
type
=
"text/javascript"
>
function expandFirstRow(grid, row) {
if (grid.$rows().index(row) == 0) {
grid.expandRow(row);
}
}
function trades_onRowDataBound(e) {
var grid = $(this).data('tGrid');
expandFirstRow(grid, e.row);
}
</
script
>
</
asp:Content
>
The LogModel class is simple class than inherits : IEnumerator, IEnumerable.
Contains ArrayList, getters, setters and IEnumerator, IEnumerable methods
here is my controller:
public
class
HomeController : Controller
{
public
ActionResult Index()
{
ViewData[
"StartDate"
] =
new
DateTime(2011, 10, 12).ToString(
"dd/MM/yyyy"
);
ViewData[
"EndDate"
] =
new
DateTime(2011, 10, 13).ToString(
"dd/MM/yyyy"
);
return
View();
}
[AcceptVerbs(HttpVerbs.Post)]
public
ActionResult Search(FormCollection formValues)
{
var txbStart = formValues[
"StartDate"
];
var txbEnd = formValues[
"EndDate"
];
ViewData[
"StartDate"
] = txbStart;
ViewData[
"EndDate"
] = txbEnd;
LogReaderTest.Models.TradesLogModel tlm =
new
Models.TradesLogModel(
new
DateTime(2011, 10, 12),
new
DateTime(2011, 10, 13));
tlm.SearchByLogin(78);
return
View(
"Index"
, tlm);
}
public
ActionResult Home()
{
return
View();
}
[GridAction]
public
ActionResult _Trades()
{
LogReaderTest.Models.TradesLogModel tlm =
new
Models.TradesLogModel(
new
DateTime(2011, 10, 12),
new
DateTime(2011, 10, 13));
tlm.SearchByLogin(43);
return
View(
"Index"
, tlm);
}
[GridAction]
public
ActionResult _Orders(
int
id)
{
LogReaderTest.Models.OrdersLogModel olm =
new
Models.OrdersLogModel(
new
DateTime(2011, 10, 12),
new
DateTime(2011, 10, 13));
olm.SearchLogBy_Mt_Id(id);
return
View(
"Index"
, olm);
}
}
OrdersLogModel and TradesLogModel are inherid from
LogModel
ToDataView
method
public
DataView ToDataView
{
get
{
DataTable dt =
new
DataTable();
dt.Columns.Add(
"Id"
,
typeof
(
int
));
dt.Columns.Add(
"DateTime"
,
typeof
(
string
));
dt.Columns.Add(
"Ms"
,
typeof
(
int
));
dt.Columns.Add(
"Type"
,
typeof
(
string
));
dt.Columns.Add(
"Message"
,
typeof
(
string
));
foreach
(LogReaderTest.Models.LogLine d
in
log)
{
dt.Rows.Add(d.Id, d.Datetime.ToString(
"dd/MM/yyyy HH:mm:ss.fff"
), d.Milliseconds, d.Type, d.Message);
}
DataView dv =
new
DataView(dt);
return
dv;
}
}
Best regards Paul.