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

ListView with editor template for foreign key type

1 Answer 153 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Steton
Top achievements
Rank 1
Steton asked on 17 Sep 2013, 04:24 PM
Hello, I am having an issue where I have not been able to associate a selected item from a DropDownList to the submitted values of an editor template from my ListView.

Partial view that renders the ListView:
@(Html.Kendo().ListView<CorrectiveActionItemModel>()
    .Name("corrective-action-items-listview")
    .TagName("div")
    .ClientTemplateId("corrective-action-item-view-template")
    .DataSource(dataSource => dataSource
        .Model(model =>
            {
                model.Id("CorrectiveActionItemID");
                model.Field(f => f.CorrectiveActionPlanID).DefaultValue(this.Model.CorrectiveActionPlanID);
                model.Field(f => f.CorrectiveActionItemType);
            })
        .PageSize(1)
        .Create(create => create.Action("Item_Create", "CorrectiveActionItem", new { this.Model.CorrectiveActionPlanID }))
        .Read(read => read.Action("Items_Read", "CorrectiveActionItem", new { this.Model.CorrectiveActionPlanID }))
        .Update(update => update.Action("Item_Update", "CorrectiveActionItem"))
        .Destroy(destroy => destroy.Action("Item_Destroy", "CorrectiveActionItem"))
    )
    .Pageable()
    .Editable())
Editor Template for CorrectiveActionItemModel:
@using Steton.Web.MVC.Model
 
@model CorrectiveActionItemModel
 
<div class="corrective-action-item-display">
    <div class="edit-buttons">
        <a class="k-button k-button-icontext k-update-button" href="\\#"><span class="k-icon k-update"></span></a>
        <a class="k-button k-button-icontext k-cancel-button" href="\\#"><span class="k-icon k-cancel"></span></a>
    </div>
     
    @Html.HiddenFor(m => m.CorrectiveActionItemID)
    @Html.HiddenFor(m => m.CorrectiveActionPlanID)
 
    <div class="action-section">
        @Html.LabelFor(m => m.DirectiveText)
        @Html.TextAreaFor(m => m.DirectiveText)
    </div>
    <div class="action-section">
        @Html.LabelFor(m => m.ActionTakenText)
        @Html.TextAreaFor(m  => m.ActionTakenText)
    </div>
    <div class="action-section">
        <div style="clear:both">
            <div class="action-sub-edit-section">
                <div>
                    @Html.LabelFor(m => m.DueDate)
                    @(Html.Kendo().DatePicker()
                          .Name("DueDate")
                          .Value("12/31/2013"))   
                </div>
                <div>
                    @Html.LabelFor(m => m.IsCompleted)
                    @Html.CheckBoxFor(m => m.IsCompleted)
                </div>
            </div>
            <div class="action-sub-edit-section">
                <div>
                    @Html.LabelFor(m => m.CorrectiveActionItemType)
                    @Html.EditorFor(m => m.CorrectiveActionItemType)
                </div>
            </div>
        </div>
    </div>
</div>
Editor template for CorrectiveActionItemType:
@using System.Collections
 
@(Html.Kendo().DropDownList()
    .Name("CorrectiveActionItemType")
    .DataTextField("TypeName")
    .DataValueField("CorrectiveActionItemTypeID")
    .DataSource(read => read.Read("Types","CorrectiveActionItem", new { correctiveActionPlanID = "#=CorrectiveActionPlanID#" })))
Now, when the CorrectiveActionItemModel is submitted I do not get any item in the POST for CorrectiveActionItemType. I suspect that there is some binding or setup that needs to occur in order to get the DropDownList's value to be associated to the model of CorrectiveActionItemModel.

I have tried following the pattern at Editor template documentation, but I could not get the .BindTo((IEnumerable)ViewData["CorrectiveActionType"])) even though I added it the controller that renders the ListView.

Any thoughts or ideas would be appreciated, thanks.

 

1 Answer, 1 is accepted

Sort by
0
Accepted
Daniel
Telerik team
answered on 19 Sep 2013, 11:00 AM
Hello,

You should use the DropDownListFor helper instead of the DropDownList helper. 

@model MyFieldType
 
@(Html.Kendo().DropDownListFor(model=> model)
    .DataTextField("TypeName")
    .DataValueField("CorrectiveActionItemTypeID")
Since the EditorFor helper is used, the prefix in the editor will be the property name, and so the property that will actually be edited will be "CorrectiveActionItemType.CorrectiveActionItemType" when setting the name.

Regards,
Daniel
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
ListView
Asked by
Steton
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or