使用不同模型的MVC3 Razor局部视图

时间:2011-11-16 05:27:17

标签: asp.net-mvc-3 partial-views telerik-grid telerik-mvc razor

提供一些背景信息:

Details.cshtml包含一个标题(使用模型类别),我有一个使用Telerik MVC3网格的部分视图,我想在其上实现Ajax功能(在任何地方使用Razor都没有文档)并为类别加载CategoryItems在Details.cshtml上使用的模型,但无法在任何地方找到有关MVC的部分视图的文档。

Details.cshtml

@model TestStore.Models.Category

@{
    ViewBag.Title = "Details";
}

<fieldset>
    <legend>Category</legend>

    <div class="display-label">Name</div>
    <div class="display-field">@Model.Name</div>

    <div class="display-label">CreatedDate</div>
    <div class="display-field">@String.Format("{0:g}", Model.CreatedDate)</div>   
</fieldset>

    @Html.Partial("CategoryItemsList", Model.CategoryItems) // this is the line I have no clue for
<p>
    @Html.ActionLink("Edit", "Edit", new { id=Model.Id }) |
    @Html.ActionLink("Back to List", "Index")
</p>

CategoryItemsList.cshtml

@model IEnumerable<TestStore.Models.CategoryItem>

@(
    Html.Telerik().Grid(Model).Name("ItemGrid")
        .DataKeys(dataKeys => dataKeys.Add(o => o.Id))
        .Columns(columns => 
        {
            columns.Bound(o => o.Id).Hidden(true);         
            columns.Bound(o => o.Name);
            columns.Bound(o => o.CreatedDate);
        })
        .DataBinding(dataBinding =>
                                dataBinding.Ajax().Select("_AjaxBinding", "ItemGrid")
                    )
        .Pageable()
        .Sortable()
    )

现在,我的问题是...使用不同的模型调用部分视图而不向其发送数据的正确语法是什么,因为我希望通过Ajax调用加载...

如果已经被要求/回答,那么很多道歉......

1 个答案:

答案 0 :(得分:2)

相关问题