0
Good afternoon guys, I have the following code:
[HttpGet]
public JsonResult ObterGridParceirosComPaginacao(PaginacaoVueTableViewModel filtro)
{
Resultado resultado = new Resultado();
var viewModel = new PaginacaoVueTableRetornoViewModel();
return Json(viewModel);
}
With the following Viewmodel:
public class PaginacaoVueTableViewModel
{
private int page;
private string orderBy;
public int Page
{
get
{
return page;
}
set
{
page = value > 0 ? value - 1 : value;
}
}
public string OrderBy
{
get
{
return orderBy;
}
set
{
orderBy = value == null ? string.Empty : value;
}
}
}
The body of the method Obtaindparceiroscompagination is not yet implemented, but my problem is when I receive Viewmodel as a parameter, the setters are not applying the rules that are set in them. I put some breakpoints and realized that at no time the getters and setters are called, so they don’t apply the rules. Does anyone know what it could be?
Note: The Viewmodel comes with all the correct values, sent from Javascript, I just need these values to pass the validations of getters and setters.
setters make no change without being called
– Lucas Miranda
But isn’t there some way I can call them? Or is there some better way to do what I’m trying to do?
– Brayan
The problem is that the parameter
filtros
null arrives? If so, the problem should be mapping from JSON to C#class. In ASP.Net Core, using json{
 "page":1,
 "orderBy":"teste"
}
worked because the mapping rule is Camelcase for Pascalcase. If you want a JSON other than this one, you can use Jsonproperty to explicitly tell . Net what the Json name of the property is.– rogerdossantos
to call the Setter in your case just put the name of the property, and then the moment it sets it will make its logic there ex: filter.Orderby = null; //when you do this here it will fill in with ""
– Lucas Miranda
So the filters parameter, it comes filled, but it does not apply the rules that are in the setters, for example, if I send from Javascript the attribute Page with the value 10, according to the rule it should turn 9, but it is maintained as 10, ie the rule was not executed. And at no time does he stop at the breakpoint I put on Setter.
– Brayan