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

[Solved] mvc grid razor - edit inline

3 Answers 84 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.
Francesca
Top achievements
Rank 1
Francesca asked on 20 Mar 2012, 09:58 AM
Hi! I have this grid_
    @(Html.Telerik().Grid(Model.SearchLedgerResults)
                .Name("LedgerGrid")
        .DataKeys(Keys =>
        {
            Keys.Add(c => c.InvoiceNr);
        })       
        .DataBinding(dataBinding =>
            {
                dataBinding.Server()
                    .Update("UpdateInvoice", "Ledger");
            })
 
        .Columns(columns =>
        {
            columns.Bound(inv => inv.InvoiceNr).Width(100);
            columns.Bound(inv => inv.Amount).Width(200);
            columns.Bound(inv => inv.AmountIn).Width(200);
            columns.Command(commands =>
            {
                commands.Edit().ButtonType(GridButtonType.Image);             
            }).Width(180).Title("Commands");
        })
        .Editable(editing => editing.Mode(GridEditMode.InLine))
        .Pageable(paging => paging.PageSize(20))
        .Scrollable(scrolling => scrolling.Height(580))
        .Sortable()
)

          
And following action in controller named Ledger:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult UpdateInvoice(int invoiceNr)
{
    var model = new LedgerModel();
    model.InvoiceDetail = new bcInvoiceDetail() { InvoiceNr = invoiceNr };
    if (TryUpdateModel(model.InvoiceDetail))
    {
        var d = new bcLedgerFunctions().UpdateInvoice_Payed(model.InvoiceDetail, "PG", 7, CurrentUserId, CurrentBoatClubId);
    }
    return IndexModel(model);
}

But the Action does not run when I hit the save button in the grid... Any suggestions? Something I'm missing?

kind regards
Francesca Backmalm

3 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 23 Mar 2012, 09:13 AM
Hello Francesca,

The most likely cause for the problem is that the Grid sends the datakey with the MVC default parameter name "Id" unless it is specified with the RouteKey configuration method. For example:
Keys.Add(c => c.InvoiceNr).RouteKey("InvoiceNr");
Could you check if setting the key name resolves it?

Greetings,
Daniel
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now.
0
Francesca
Top achievements
Rank 1
answered on 26 Mar 2012, 02:08 PM
Thank you Daniel for your reply, I added the code as you suggested:
 .DataKeys(keys => keys.Add(o => o.InvoiceNr).RouteKey("InvoiceNr")) 

bu it still doesn't work...

Regards,
Francesca
0
Daniel
Telerik team
answered on 27 Mar 2012, 01:22 PM
Hello again Francesca,

I am not sure. Is the request being made at all? If yes, what is the result returned from the Update action method? It would be helpful if you could send a sample project which reproduces the problem so I can check the setup.

Kind regards,
Daniel
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now.
Tags
Grid
Asked by
Francesca
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Francesca
Top achievements
Rank 1
Share this question
or