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

[Solved] Editor Template with DropDownListFor

0 Answers 70 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.
Michael
Top achievements
Rank 1
Michael asked on 25 Apr 2011, 09:56 PM
Hello,

     I am having a problem figuring out how to use a DropDownList in my Editor Template for an Telerik Mvc Grid. Here is what I have so far. Basically a StoreMessageDto has a CategoryMessageDto as a member. I need to choose from a list of CategoryMessageDto so that the selected CategoryMessageDto becomes the member CategoryMessageDto.

Partial with grid:

@model IList<GeoDeals.Services.Interfaces.IStoreMessageDto>     
@using Telerik.Web.Mvc.UI   

@(Html.Telerik().Grid<GeoDeals.Services.Dtos.StoreMessageDto>()
        .Name("StoresGrid")
        .DataKeys(keys => keys.Add(s => s.StoreId))
        .ToolBar(commands => commands.Insert().ButtonType(GridButtonType.Text).ImageHtmlAttributes(new { style = "margin-left:0" }))        
        .DataBinding(dataBinding => dataBinding.Ajax()
                                            .Select("GetStores", "Store")
                                            .Insert("Create", "Store")
                                            .Update("Update", "Store")
                                            .Delete("Delete", "Store"))
        .Columns(columns =>
        {
            columns.Bound(s => s.Name );
            columns.Command(commands =>
            {
                commands.Edit().ButtonType(GridButtonType.Text);
                commands.Delete().ButtonType(GridButtonType.Text);
            }).Width(180);
        })        
        .Pageable()
        .Scrollable()
        .Sortable()        
        .Editable(x => x.Mode(GridEditMode.PopUp))
    )

Editor Template:

@model GeoDeals.Services.Dtos.StoreMessageDto
@using Telerik.Web.Mvc.UI

<fieldset>
    <legend>Store Info</legend>
    
    @Html.HiddenFor(s => s.StoreId)
    
    <div>
        Name: @Html.EditorFor(s => s.Name)
    </div>
    <div>
        Category: @(Html.Telerik().DropDownListFor(x => x.CategoryMessageDto)
                                  .DataBinding(dataBinding => dataBinding.Ajax()
                                                    .Select("GetCategories", "Store"))
                                      
                    )
    </div>
    <div>
        Street: @Html.EditorFor(s => s.Street)
    </div>
    <div>
        City: @Html.EditorFor(s => s.City)
    </div>
    <div>
        State: @Html.EditorFor(s => s.State)
    </div>
    <div>
        Zipcode: @Html.EditorFor(s => s.Zipcode)
    </div>
    <div>
        Phone: @Html.EditorFor(s => s.PhoneNumber)
    </div>
    <div>
        Url: @Html.EditorFor(s => s.Url)
    </div>
</fieldset>

Controller Action:
       public ActionResult GetCategories()
        {
            var categories = _storeService.GetCategories(); //This returns a list of ICategoryMessageDto
            return this.Json(categories);

        }

ICategoryMessageDto:

namespace GeoDeals.Services.Interfaces
{
    public interface ICategoryMessageDto
    {
        int CategoryId { get; set; }
        string Name { get; set; }
    }
}

Tags
Grid
Asked by
Michael
Top achievements
Rank 1
Share this question
or