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

Example of editing with Custom Ajax Binding

4 Answers 71 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.
Juan Pablo Perez
Top achievements
Rank 1
Juan Pablo Perez asked on 20 May 2012, 07:09 PM
I've looking inside the forum but I couldn't find any example of editing with Custom Ajax Binding. 

Does anybody has worked with it?

Thanks in advance.

Juan Pablo

4 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 23 May 2012, 05:28 PM
Hello Juan Pablo,

There aren't example for editing and custom binding because there isn't a difference. I attached a sample project implements this scenario. The only thing that could be causing some problem is if you are using aggregates. The ModelBinder will try to parse the Aggregates parameter and will add a ModelState error which can be avoided by using the Bind attribute e.g.
[GridAction(EnableCustomBinding = true)]
public ActionResult _Update([Bind(Exclude="Aggregates")]GridCommand command, int id)

All the best,
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
Juan Pablo Perez
Top achievements
Rank 1
answered on 24 May 2012, 05:19 AM
Thank you very much Daniel. It works great! 

Now I have a problem: Is there any way to send back to the view a flag when there is an error when updating or deleting in order to show a message to ther user saying that action could not be processed?

Juan Pablo
0
Accepted
Daniel
Telerik team
answered on 28 May 2012, 03:31 PM
Hello again Juan Pablo,

By default, all model state errors are serialized and send back with the response. So in order to send a custom message, you can add a ModelState error in the action method when it cannot be processed and show the message on the client in the OnError event. e.g.
//Action
ModelState.AddModelError("errorKey","error message");
function onError(e) {
    if (e.modelState && e.modelState.errorKey) {
        alert(e.modelState.errorKey.errors[0]);           
    }
}

All the best,
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
Juan Pablo Perez
Top achievements
Rank 1
answered on 29 May 2012, 07:40 AM
Hello Daniel,

It works great! I didn't know Model State were send back .

Thanks a lot.

Kind regards,

Juan Pablo
Tags
Grid
Asked by
Juan Pablo Perez
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Juan Pablo Perez
Top achievements
Rank 1
Share this question
or