This is a migrated thread and some comments may be shown as answers.

[Solved] Model not populated in popup form

1 Answer 68 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jerry
Top achievements
Rank 1
Jerry asked on 12 Oct 2011, 06:24 PM
Here is my grid definition:
@(Html.Telerik().Grid<EditAssetEntryViewModel>()
    .Name("AssetGrid")
    .Sortable()
    .Scrollable(scroll => scroll.Height(300))
    .Pageable(paging => paging.Style(GridPagerStyles.Status).PageOnScroll(true))
    .DataKeys(keys => keys.Add(o => o.AssetEntryID))
    .Editable(e => e.Mode(GridEditMode.PopUp))
    .Columns(columns =>
    {
        columns.Bound(c => c.Description);
        columns.Bound(c => c.AssetClass).Width(200);
        columns.Bound(c => c.Shares).Width(80).Format("{0:n}").HtmlAttributes(new { style = "text-align:right;" });
        columns.Bound(c => c.MarketValue).Width(80).Title("Mkt Value").Format("{0:c}").HtmlAttributes(new { style = "text-align:right;" });
        columns.Bound(c => c.AdjustedMarketValue).Width(80).Format("{0:c}").HtmlAttributes(new { style = "text-align:right;" });
        columns.Bound(c => c.AccruedIncome).Width(80).Title("Accrued Inc").Format("{0:c}").HtmlAttributes(new { style = "text-align:right;" });
        columns.Bound(c => c.AdjustedAccruedIncome).Width(80).Format("{0:c}").HtmlAttributes(new { style = "text-align:right;" });
        columns.Command(commands =>
        {
            commands.Edit().ButtonType(GridButtonType.Image);
        }).Width(38);
        columns.Bound(c => c.MarketPrice).Hidden(true);
    })
    .DataBinding(dataBinding => dataBinding.Ajax()
        .Select("GetAssetEntries", "Statement", new { statementID = Model.StatementID })
        .Update("UpdateAssetEntry", "Statement"))
    .ClientEvents(events =>
    {
        events.OnEdit("onGridEdit");
    })
    .DetailView(detailView => detailView.ClientTemplate(
        "<div class='t-widget t-grid'>" +
            "<table cellspacing='0'>" +
                "<thead class='t-grid-header'>" +
                    "<tr>" +
                        "<th colspan='8' class='t-header'><#= Description #> <#= Description2 #></th>" +
                    "</tr>" +
                "</thead>" +
                "<tr>" +
                    "<td>Shares</td>" +
                    "<td style='text-align:right;'><#= $.telerik.formatString('{0:n}', Shares) #></td>" +
                    "<td><#= SecurityIDTypeDescription #></td>" +
                    "<td><#= SecurityID #></td>" +
                    "<td>Mkt Val</td>" +
                    "<td class='t-last' style='text-align:right;'><#= $.telerik.formatString('{0:c}', MarketValue) #></td>" +
                    "<td>Adj Mkt Val</td>" +
                    "<td class='t-last' style='text-align:right;'><#= $.telerik.formatString('{0:c}', AdjustedMarketValue) #></td>" +
                "</tr>" +
                "<tr class='t-alt'>" +
                    "<td>Mkt Price</td>" +
                    "<td style='text-align:right;'><#= $.telerik.formatString('{0:c}', MarketPrice) #></td>" +
                    "<td>Adj Mkt Price</td>" +
                    "<td style='text-align:right;'><#= $.telerik.formatString('{0:c}', AdjustedMarketPrice) #></td>" +
                    "<td>Acc Inc</td>" +
                    "<td style='text-align:right;'><#= $.telerik.formatString('{0:c}', AccruedIncome) #></td>" +
                    "<td>Adj Acc Inc</td>" +
                    "<td class='t-last' style='text-align:right;'><#= $.telerik.formatString('{0:c}', AdjustedAccruedIncome) #></td>" +
                "</tr>" +
                "<tr>" +
                    "<td>Cost</td>" +
                    "<td style='text-align:right;'><#= $.telerik.formatString('{0:c}', Cost) #></td>" +
                    "<td>Pct of Mkt</td>" +
                    "<td><#= $.telerik.formatString('{0:p}', PercentOfMarket) #></td>" +
                    "<td>Yld on Mkt</td>" +
                    "<td><#= YieldOnMarket #></td>" +
                    "<td>Asset Sector</td>" +
                    "<td class='t-last'><#= AssetSector #></td>" +
                "</tr>" +
            "</table>" +
        "</div>")
    )
)

And here is the editor template:
@model EditAssetEntryViewModel
 
<div style="padding: 20px; width: 500px; height: 250px;">
 
    <div>@Html.HiddenFor(m => m.AssetEntryID)</div>
 
    <div>@Html.DisplayFor(m => m.MarketPrice)</div>
    <div>@Html.EditorFor(m => m.AdjustedMarketPrice)</div>
</div>

I'm using this type of setup in several places and it works just fine.  But here, for somereason, when the user clicks to edit a row in the grid, the model in the editor template is not getting populated.  I verified that the dataItem is properly populated in the OnEdit event for the grid.  But I always get an empty model in the popup form.

What am I missing?

Thanks.

J

1 Answer, 1 is accepted

Sort by
0
Marc
Top achievements
Rank 1
answered on 28 Nov 2011, 11:25 PM
I was trying to figure this one out as well and couldn't get @Html.DisplayFor() to work at all. I looked through the object model and couldn't find the Model being passed to this view anywhere, even though the value is available in an editor field.

Instead I used this to get the same effect:

       @Html.TextBoxFor(item => item.Name, new {Style="border: 0px;", Readonly="readonly"})

This at least output the value to the edit form and disabled any edits by the user.

Hope that helps.

Marc
Tags
Grid
Asked by
Jerry
Top achievements
Rank 1
Answers by
Marc
Top achievements
Rank 1
Share this question
or