I would like to now the difference for ASP.net MVC between two calls of the same action :
public class VisualizzareAreaIntervento
{
public string Descrizione { get; set; }
public int PageNum { get; set; }
public int PageSize { get; set; }
}
public JsonResult GetItems(VisualizzareAreaIntervento command){
...
}
If I call it via Post, everything works fine and the aprameter command in the action is well initialised:
var command = new VisualizzareItems(descrizione,pageNum,pageSize);
$.ajax({
type: 'Post',
url: '@Url.Action("GetItems")',
data: JSON.stringify(command),
contentType: 'application/json; charset=utf-8',
success: success,
error: error,
dataType: 'json'
});
the same call with Get, gives me an command object with default values in it (“”,0,0)
var command = new VisualizzareItems(descrizione,pageNum,pageSize);
$.ajax({
type: 'Get',
url: '@Url.Action("GetItems")',
data: JSON.stringify(command),
contentType: 'application/json; charset=utf-8',
success: success,
error: error,
dataType: 'json'
});
I have looked in firebug and the object is well sent the two times. How does ASP.net MVC works this out?
thanks for your support,
Short answer: DefaultModelBinder.
Old link, but it will make you get the basics:
http://www.howmvcworks.net/OnModelsAndViewModels/TheBeautyThatIsTheModelBinder