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

Create action not being called in ListView

3 Answers 125 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Steve
Top achievements
Rank 1
Steve asked on 25 Sep 2013, 04:23 PM
I am attempting to use the Create action in ListView for MVC4 according to the Getting Started example, but the Create action does not get called. The Read, Update, and Destroy actions do get called as expected. Here is relevant code, and any help would be appreciated:
From the view:
@model VentSettings
 
<div class="k-toolbar k-grid-toolbar">
    <a class="k-button k-button-icontext k-add-button" href="#"><span class="k-icon k-add"></span>Add new record</a>
</div>
 
<script type="text/x-kendo-tmpl" id="ventTemplate">
    <div>
       <div class="edit-buttons" style="width:98%; background:lightgray; border:1px solid lightgray; padding:10px;">#:Time#
            <a style="float:right" class="k-button k-button-icontext k-edit-button" href="\\#"><span class="k-icon k-edit"></span>Edit</a>
            <a style="float:right" class="k-button k-button-icontext k-delete-button" href="\\#"><span class="k-icon k-delete"></span>Delete</a>
        </div>
 
        <div style="width: 98%; padding:10px; border:1px solid lightgray;">
            <span style="width:10%; display: inline-block">Rate:</span><span style="width:22%; display:inline-block">#:Rate#   per min</span>
            <span style="width:10%; display: inline-block">PIP:</span><span style="width:22%; display:inline-block">#:PIP#   cm H<sub>2</sub>O</span>
            <span style="width:10%; display: inline-block">PEEP:</span><span style="width:22%; display:inline-block">#:PEEP#   cm H<sub>2</sub>O</span>
            <span style="width:10%; display: inline-block">MAP:</span><span style="width:22%; display:inline-block">#:MAP#   cm H<sub>2</sub>O</span>
            <span style="width:10%; display: inline-block">Vent:</span><span style="width:50%; display:inline-block">#:VentDescription# </span>
        </div>
    </div>
</script>
 
@(Html.Kendo().ListView<VentSetting>(Model.VentSettingsList)
    .Name("listView")
    .TagName("div")
    .ClientTemplateId("ventTemplate")
    .Editable()
    .DataSource(datasource => datasource
        .Events(events => events.Sync("handleSync"))
        .Model(model => model.Id(m => m.VentSettingId))
        .Read(read => read.Action("ReadVentSettings", "RunDetail"))
        .Create(create => create.Action("CreateVentSetting", "RunDetail"))
        .Update(update => update.Action("UpdateVentSetting", "RunDetail"))
        .Destroy(destroy => destroy.Action("DeleteVentSetting", "RunDetail"))
    )
)
 
<script>
 
function handleSync() {
    this.read();
}
 
</script>
The relevant part of the EditorTemplate:
<div style="padding:10px">
    @Html.ValidationSummary(true)
     
    <span style="width:12%; display:inline-block">Resp Rate: </span>
     <span style="width:36%; display:inline-block"> @Html.Kendo().DropDownListFor(x => x.VentTypeId).DataValueField("VentTypeId").DataTextField("Description").BindTo((System.Collections.IEnumerable)ViewData["VentTypes"])</span>
     
 
    <div class="edit-buttons">
        <a class="k-button k-button-icontext k-update-button" href="\\#"><span class="k-icon k-update"></span>Save</a>
        <a class="k-button k-button-icontext k-cancel-button" href="\\#"><span class="k-icon k-cancel"></span>Cancel</a>
    </div>
 
</div>
From the controller, the Create action (does not get called) and the Update action (gets called). I've tried the Create action with and without the second parameter:
[HttpPost]
public ActionResult CreateVentSetting([DataSourceRequest] DataSourceRequest request, Models.VentSetting modelVentSetting)
{
    if (modelVentSetting != null && ModelState.IsValid)
    { // Create code... }
 
    return Json(ModelState.ToDataSourceResult());
}
 
[HttpPost]
public ActionResult UpdateVentSetting([DataSourceRequest] DataSourceRequest request, Models.VentSetting modelVentSetting)
{
    // Update code...
 
    return Json(ModelState.ToDataSourceResult());
}
Thanks in advance!
Steve

3 Answers, 1 is accepted

Sort by
0
Accepted
Steve
Top achievements
Rank 1
answered on 27 Sep 2013, 01:33 AM
I have obtained a solution to the problem, with the answer discussed in this post.
0
Mike
Top achievements
Rank 1
answered on 28 Jun 2017, 03:47 PM

Hi,

thanks for posting the link to the solution.
i'm having the same issue with my Update function on the controller.
Create and Read get called (with parameter objects).

But Destroy and Update not.

http://www.telerik.com/forums/listview-not-calling-update-controller-action#KH-kmJunoUO89cKXu7fpzg

@(Html.Kendo().ListView<AddressViewModel>()
    .Name("partnerOtherAddresses")
    .TagName("div")
    .ClientTemplateId("addressTemplate")
    .Editable()
    .DataSource(dataSource => dataSource
        .Model(model => model.Id("AddressId"))
        .PageSize(6)
        //.ServerOperation(false)
        .Events(events => events.Sync("handle_sync"))
        .Create(create => create.Action("Address_Create", "PartnerOther"))
        .Read(read => read.Action("Address_Read", "PartnerOther", new { id = Model.PartnerId }))
        .Update(update => update.Action("Address_Update", "PartnerOther"))
        .Destroy(destroy => destroy.Action("Address_Delete", "PartnerOther"))
    )
      .Pageable(pageable => pageable
          .PageSizes(new List<object> { 3, 6, 9, 12, 50 })
          .Refresh(true))
      )

0
Preslav
Telerik team
answered on 30 Jun 2017, 11:28 AM
Hello Alain,

I should let you know that my colleagues already answered in the ticket on the same topic. That said, I believe that it would be better to keep all the information and details in a single thread.

Once we get to the bottom of this, you could update this forum with the solution. This might help someone from the community if he or she encounters a similar problem in the future.

Regards,
Preslav
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
ListView
Asked by
Steve
Top achievements
Rank 1
Answers by
Steve
Top achievements
Rank 1
Mike
Top achievements
Rank 1
Preslav
Telerik team
Share this question
or