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

[Remote] not working in grid?

4 Answers 90 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.
Joan Vilariño
Top achievements
Rank 2
Joan Vilariño asked on 22 Feb 2011, 12:06 PM
Hi... I have an ajax grid as follows :

@(Html.Telerik().Grid<TraspasoViewModel.TraspasoAlbaranesCandidatosVM>()
                .Name("GridCandidatos")
                .DataKeys(k => k.Add(o => o.IdCentroServicio))
                .DataBinding(db => db.Ajax().Select<TraspasoController>(o => o._obtenerGridCandidatos())
                                            .Update<TraspasoController>(o => o._updateGridCandidatos(0))
                                            .Delete<TraspasoController>(o => o._deleteGridCandidatos(0)))
                .Sortable()
                .Filterable()
                .Reorderable(cf => cf.Columns(true))
                .Resizable(cf => cf.Columns(true))
                .Scrollable(sc => sc.Height(450))
                .Pageable(pg => pg.PageSize(50))
                .Selectable()
                .Columns(cl =>
                {
                    cl.Command(cm =>
                    {
                        cm.Edit().ButtonType(GridButtonType.Image);
                        cm.Delete().ButtonType(GridButtonType.Image);
                    }).Width(80).Title("Acciones");
                    cl.Bound(o => o.Empresa).ReadOnly().Width(90);
                    cl.Bound(o => o.Tercero).ReadOnly().Width(90);
                    cl.Bound(o => o.NomLocal).ReadOnly().Width(250);
                    cl.Bound(o => o.NomTitular).ReadOnly().Width(250);
                    cl.Bound(o => o.Modelo).ReadOnly().Width(100);
                    cl.Bound(o => o.NumeroSerie).ReadOnly().Width(100);
                    cl.Bound(o => o.Propuesto).ReadOnly().Width(100).HtmlAttributes(new { style = "text-align:right" });
                    cl.Bound(o => o.Importe).HtmlAttributes(new { style = "text-align:right" });
                }))

With this ViewModel:
public class TraspasoAlbaranesCandidatosVM : EntidadVM
      {
          public long IdCentroServicio { get; set; }
          public string Codigo { get; set; }
          public string Nombre { get; set; }
          public long IdEmpresa { get; set; }
          [Display(ResourceType = typeof(TraspasoStrings), Name = @"TraspasoAlbaranesCandidatosVM_Empresa")]
          public string Empresa { get; set; }
          public string NomEmpresa { get; set; }
          public long IdLocal { get; set; }
          public string Local { get; set; }
          [Display(ResourceType = typeof(TraspasoStrings), Name = @"TraspasoAlbaranesCandidatosVM_NomLocal")]
          public string NomLocal { get; set; }
          public long IdTercero { get; set; }
          [Display(ResourceType = typeof(TraspasoStrings), Name = @"TraspasoAlbaranesCandidatosVM_Tercero")]
          public string Tercero { get; set; }
          public string NomTercero { get; set; }
          public long IdMaquina { get; set; }
          [Display(ResourceType = typeof(TraspasoStrings), Name = @"TraspasoAlbaranesCandidatosVM_Modelo")]
          public string Modelo { get; set; }
          [Display(ResourceType = typeof(TraspasoStrings), Name = @"TraspasoAlbaranesCandidatosVM_NumeroSerie")]
          public string NumeroSerie { get; set; }
          public long IdTitular { get; set; }
          public string Titular { get; set; }
          [Display(ResourceType = typeof(TraspasoStrings), Name = @"TraspasoAlbaranesCandidatosVM_NomTitular")]
          public string NomTitular { get; set; }
          [Display(ResourceType = typeof(TraspasoStrings), Name = @"TraspasoAlbaranesCandidatosVM_Importe")]
          [Remote("_comprobarImporte", "Traspaso", "Recaudacion", AdditionalFields = "Propuesto", ErrorMessageResourceType = typeof (TraspasoStrings), ErrorMessageResourceName = "TraspasoAlbaranesCandidatosVM_Importe_El_importe_no_puede_superar_la_cantidad_propuesta_")]
          public decimal Importe { get; set; }
          [Display(ResourceType = typeof(TraspasoStrings), Name = @"TraspasoAlbaranesCandidatosVM_Propuesto")]
          public decimal Propuesto { get; set; }
          public TraspasoAlbaranesCandidatosVM() : this(new TraspasoAlbaranesCandidatosGrid()) {}
          public TraspasoAlbaranesCandidatosVM(TraspasoAlbaranesCandidatosGrid entidad): base(entidad)
          {
              this.Propuesto = entidad.Importe;
          }
      }

And this action in my controller:

public ActionResult _comprobarImporte(decimal Importe, decimal Propuesto)
       {
           return Json((Propuesto < 0)
                           ? (Importe >= Propuesto)
                           : (Propuesto >= Importe), JsonRequestBehavior.AllowGet);
       }

As you can see, I'm defining a [Remote] validator for field "Importe" that will pass an AdditionalField called "Propuesto", both present at model and grid. The problem is that even when the controller's action is called for validation, "Propuesto" always comes as null.

If I define it as "decimal" at my action... I get a 500 server error, then I changed it for "string" and I saw that the problem is that "Propuesto" always comes as null.

Then checking the HTML at edit time, I saw that the .ReadOnly column for "Propuesto" is rendering its value as plain text, so I thought the problem was that I needed to make propuesto editable (not what I need but okay for testing purposes). So I removed the .ReadOnly attribute from "Propuesto"'s column, but the result is the same: "Propuesto" always comes null to the validation action.

I also tried to change the [Remote]'s HttpMethod to POST, and the result is the same... in fact, when I check "Request.Form" at my action, only "Importe" comes in the collection.

Can you fix that or teach me a workaround, please?

Cheers

4 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 22 Feb 2011, 05:27 PM
Hi Joan Vilariño,

I was able to observed similar to the described behavior. However, we have managed to address it and the fix will be included in the next official version of the component. Meanwhile, you can  substitute telerik.grid.editing.js file with the attached version. I have updated your telerik points too.

All the best,
Rosen
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Joan Vilariño
Top achievements
Rank 2
answered on 23 Feb 2011, 09:33 AM
Hi there.

With the patch you supplied it works, but only partially. When the columns with the AdditionalFields are editable all is correct, but if the columns having the AdditionalFields are .Readonly() the AdditionalFields values won't be sent to the validator... I had to do something like this:

cl.Bound(o => o.MyAdditionalField).ReadOnly().ClientTemplate("<#=MyAdditionalField#><input type='hidden' name='MyAdditionalField' value='<#=MyAdditionalField#>' />"));

Is that the expected behavior??? I find it pretty complicated ...

Cheers
0
Rosen
Telerik team
answered on 23 Feb 2011, 01:40 PM
Hello Joan Vilariño,

Yes this is expected. Remote validation requires the additional fields to be presents as input elements.

All the best,
Rosen
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Juan Pablo Perez
Top achievements
Rank 1
answered on 04 Mar 2011, 09:22 PM
Hello Joan,

I used to have a problem similar to it and I solved it putting the Model as parameter instead of each parameter individually. MVC fills the values you have put in the attribute Remote.

Try something like this:

public ActionResult _comprobarImporte(TraspasoViewModel model)
       {
           return Json((model.Propuesto < 0)
                           ? (model.Importe >= model.Propuesto)
                           : (model.Propuesto >= model.Importe), JsonRequestBehavior.AllowGet);
       }

I hope this works for you.

Juan Pablo Pérez
Tags
Grid
Asked by
Joan Vilariño
Top achievements
Rank 2
Answers by
Rosen
Telerik team
Joan Vilariño
Top achievements
Rank 2
Juan Pablo Perez
Top achievements
Rank 1
Share this question
or