0
votes

I have an ASP.NET MVC3 View that has a Telerik Grid that uses a viewmodel for its data.

One of the requirements is that we need a dropdown control in one of the grid columns which gets data from a lookup table.

Being relatively new to MVC3, I figured that since the Razor View can only use one model directive IE:

@model IEnumerable<MarketingWebsiteTools.Models.EditableItemInfo>

that the dropdown lookup valueswould need to be mapped back to the ViewModel along with the data for the grid.

At this point it might be pertinent to mention that I'm using Html.Telerik().ComboBox() in a ClientTemplate like this:

    .Columns(columns =>
    {
    columns.Bound(o => o.ItemNmbr).Width(65);//.ClientTemplate("<label  name='ProductIdentifier' />");
    columns.Bound(o => o.Description).Width(65)
                .ClientTemplate(Html.Telerik().ComboBox()
                .Name("Special")
                **.BindTo(new SelectList())**
                .ToHtmlString());
    columns.Bound(o => o.Start_Date).Width(75).Format("{0:d}");
    columns.Bound(o => o.End_Date).Width(75).Format("{0:d}");
    columns.Bound(o => o.PromotionText).Width(75);
    columns.Command(commands => commands.Delete()).Width(125).Title("Delete");
    })

My question is: In respect to the BindTo(new SelectList()), I need to provide a parameter of type System.Collections.Generic.IEnumerable, however I'm unsure how to get that from my viewmodel, or perhaps, I should be getting that lookup data another way...

I looked at this example: http://www.telerik.com/community/forums/aspnet-mvc/combobox/bindto.aspx

However, My code or intellisense doesn't seem to be recognizing any models IE: .BindTo(new SelectList(Model.))

I also looked at this example: How to insert drop down list box in a Telerik grid

where it looks like there's a call to a method in a controller, but again, no access to that controller..

thanks in advance for any help.

doug

1

1 Answers

0
votes

You can do it very easy using Template. From Controller just using a TempData or ViewBag to pass data to the View.

@{
    List<AdjustmentReasonCodes> salesAuditReasons = new List<AdjustmentReasonCodes>();
    salesAuditReasons = (List<AdjustmentReasonCodes>)TempData["SalesAuditReason"];
}

column.Template(@<select id="@("ddlSalesAuditReason" + @item.CustCode.Replace(" ", "").Replace("-", "").Trim())" class="DropDown">
                    <option value="0">--Select--</option>
                    @foreach (AdjustmentReasonCodes adrc in salesAuditReasons)
                    {
                        if (item.RefReasonForAuditAdjustment == adrc.ReasonCode)
                        { 
                        <option value="@(adrc.ReasonCode)" selected="selected">@adrc.ReasonDescription</option> 
                        }
                        else
                        {                        
                        <option value="@(adrc.ReasonCode)">@adrc.ReasonDescription</option>
                        }
                    }
                </select>).Title("Audit Reason").Width(135);