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

[Solved] MVC3 Telerik Grid and Areas

0 Answers 65 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.
Neil Watts
Top achievements
Rank 1
Neil Watts asked on 09 Mar 2012, 10:07 PM
Hello:

I have an MVC3 razor app using the Telerik Grid. When I go into edit mode I need to bind several dropdownlists. Since I am using areas, where do I put my EditorTemplates?

I am having a terrible time getting them to bind. I either get the ddlist is undefined or just nothing happens.

Also the naming convention just to make sure I have it riight.

My grid is bound to Model XYZ
If I am binding columns.Bound(o => o.SubAssemblyName) and I need a dropdown in editmode, does my edittemplate file need to be named according to my grid model or according to a model that is just SubAssembly data.

So would my edit template be ModelXYZ.cshtml or SubAssemblies.cshtml ?

And anywhere I reference that dropdown should be SubAssemblyName, is that correct?

Also this is a details grid, not sure if that makes any difference or not.

Sorry to post so many things, but from all the examples I have seen it doesnt really explain these things.

Code is below

---Grid---
    .ClientTemplate(Html.Telerik().Grid<SubAssemblies_X_Programs_Assemblies_Builds_Grid>()
        .Name("Attached_<#= AssemblyID #>")
        .Columns(columns =>
        {
            columns.Command(commands =>
            {
                commands.Edit().ButtonType(GridButtonType.Image);
            }).Width(80);
 
            columns.Bound(o => o.SubAssemblyName)
                .Title("Sub Assembly Name")
                .Width(75)
                .HtmlAttributes(new { style = "text-color: #000000" })
                .HtmlAttributes(new { style = "text-align:left" });
            columns.Bound(o => o.SubAssemblyTypeName)
                .Title("Sub Assembly Type")
                .Width(75)
                .HtmlAttributes(new { style = "text-color: #000000" })
                .HtmlAttributes(new { style = "text-align:left" });
            columns.Bound(o => o.Qty)
                .Title("Quantity")
                .Width(50)
                .HtmlAttributes(new { style = "text-color: #000000" })
                .HtmlAttributes(new { style = "text-align:left" });
            columns.Bound(o => o.CostPerSubAssembly)
                .Title("Cost")
                .Width(50)
                .HtmlAttributes(new { style = "text-color: #000000" })
                .HtmlAttributes(new { style = "text-align:left" });
        }).Resizable(resize => resize.Columns(true))
        .ToolBar(commands => commands.Insert()
            .ButtonType(GridButtonType.ImageAndText)
            .ImageHtmlAttributes(new { style = "margin-left:0" }))
        .DataBinding(dataBinding => dataBinding.Ajax()
            .Select("_AjaxAttachedSubAssemblies", "BuildManager", new { assemblyID = "<#= AssemblyID #>" })
            .Insert("_AjaxAddAttached", "BuildManager", new { assemblyID = "<#= AssemblyID #>" })
            .Update("_AjaxEditAttached", "BuildManager", new { assemblyID = "<#= AssemblyID #>" }))
        .DataKeys(keys => keys
            .Add(o => o.SubAssemblyID)
                .RouteKey("SubAssemblyID"))
        .ClientEvents(events => events
            .OnError("onError")
            .OnDataBound("onDataBoundAttached")
            .OnEdit("onEditAttached")
            .OnDataBinding("OnDataBindingAttached"))
        .Pageable(pagerAction => pagerAction.PageSize(15))
        .Editable(editing => editing.Mode(GridEditMode.PopUp))
        .Sortable()
        .Filterable()
        .Footer(true)
        .HtmlAttributes(new { style = "margin-bottom: 1.3em" })
        .ToHtmlString()
))
.Render();

---EditTemplate---
@(Html.Telerik().DropDownList()
        .Name("SubAssemblyName")
        .HtmlAttributes(new { style = "width:300px" })
        .BindTo(new SelectList((IEnumerable)ViewData["SubAssembly"], "SubAssemblyID", "SubAssemblyName"))
)

---onEdit---
function onEditAttached(e) {
    $(e.form).find('#SubAssemblyName').data('tDropDownList').select(function (dataItem) {
        return dataItem.Text == e.dataItem['SubAssemblyName'];
    });
}


Thanks in advance
Tags
Grid
Asked by
Neil Watts
Top achievements
Rank 1
Share this question
or