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

[Solved] Server databinding problem (edit and update)

3 Answers 114 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.
Pål
Top achievements
Rank 1
Pål asked on 18 Jan 2011, 09:55 PM
Hi,

I have a view strongly typed to a viewmodel. This model has a Loan object which in turn has a list of LoanEvents. The view displays information about the Loan and a grid of LoanEvents. When binding I have managed to insert new LoanEvents but cannot get the edit/update part to work.

Here is my code:
<%: Html.Telerik().Grid(Model.Loan.LoanEvents)
                .Name("LoanEvents")
        .DataKeys(keys => keys.Add(le => le.ID))
                .ToolBar(commands => commands.Insert())
        .DataBinding(databinding => databinding.Server()
                                            .Select("Details""Loan"new {id = Model.Loan.ID})
                                            .Insert("CreateEvent""Loan"new { id = Model.Loan.ID })
                                            .Update("Edit""LoanEvent")
                                            .Delete("Delete""LoanEvent"))
        .Columns(columns =>
                            {
                                columns.Bound(p => p.Created);
                                        columns.Bound(p => p.Action).Width(130).Title("Type");
                                        columns.Bound(p => p.Comment).Width(300).Title("Kommentar");
                                        columns.Bound(p => p.Officer.FullName).Width(130).Title("RÃ¥dgiver");
                                        columns.Command(commands => commands.Edit()).Width(180).Title("");
                                    })
                .Editable(editing => editing.Mode(GridEditMode.InLine))
                .Pageable(paging => paging.PageSize(10))
                .Sortable(sorting => sorting.OrderBy(sortOrder => sortOrder.Add(le => le.Created).Descending()))
        .Filterable()
        %>

When pushing the edit button in the grid the Details action in the LoanController is fired, with the LoanEvents id as parameter. Which of course breaks as the Loan's Id doesn't correspond to the LoanEvent's Id.

What is needed? Will the action of the Select binding always fire?

Best regards
PÃ¥l Eilertsen


3 Answers, 1 is accepted

Sort by
0
Laurent
Top achievements
Rank 1
answered on 17 Apr 2013, 05:36 PM
I have exactcly the same problem today. With MVC3, last version of Telerik...

I start to be mad here.
0
Laurent
Top achievements
Rank 1
answered on 17 Apr 2013, 05:57 PM
My Page : 

<%= Html.Telerik().Grid(Model).Name("grid").HtmlAttributes(new { style = "width: 60%" })
    .DataKeys(keys => keys.Add(t => t.TranslateID))
        .DataBinding(data => data.Server().Update("UpdateTranslation", "Translation"))
    .Columns(columns =>
    {
        columns.Bound(o => o.Field).Width(200).ReadOnly();
        columns.Bound(o => o.FriendlyName).Width(250);
        columns.Bound(o => o.IsActive).Width(100);
        columns.Command(commands => commands.Edit()).Width(100);
    })
    .Editable(editing => editing.Mode(GridEditMode.InLine))
    .Footer(false) %>

My controller : 

public ActionResult ContactTranslation()
{
    return View(TranslationManager.GetAll());
}
 
[HttpPost]
public ActionResult UpdateTranslation(int id)
{
    DAM_TRANSLATE_CONTACT tr = new DAM_TRANSLATE_CONTACT();
    tr.TranslateID = id;
 
    if (TryUpdateModel(tr))
    {
        TranslationManager.UpdateTranslation(tr);
 
        return View("ContactTranslation", TranslationManager.GetAll());
    }
 
    return View("ContactTranslation", TranslationManager.GetAll());
}

The problem is simple : 
Either Ajax or Server databindings are working. 

The "inline" edition components are correctly shown when clicking on "Edit". THen I change the second columns (FriendlyName), then I click on "Update" : all the page is drawing again without calling my controller action "UpdateTranslation". And the row that I was editing still in "edit" mode.

Please help me, I am on this since 5 hours now !
Laurent.
0
Laurent
Top achievements
Rank 1
answered on 17 Apr 2013, 09:06 PM
PLease somoene, help me.

This application has to be finished tomorrow, and I have lost enough time on this :(.

Thanks in advance ! 
Tags
Grid
Asked by
Pål
Top achievements
Rank 1
Answers by
Laurent
Top achievements
Rank 1
Share this question
or