I have the following code:
return Json(new {
ent = vm.ent,
errors = e.Message,
fld = vm.fld,
pk = vm.pk,
success = false,
rk = vm.rk,
_rk = _rk,
val = vm.val
});
The code works but I am wondering if I can do this with a class instead of an anonyomous array. It just seems that with the anonymous way there is no checking for the field names.
You can return whatever class you want. I have not tested it but it would not make sense to only work with anonymous class. More to the point it seems the easies thing to try if you have a project running.
I don’t know what exactly you mean by “checking for field names” but you can use anonymous classes like this:
In this case the property of the anonymous class takes the name of the property that was assigned.
P.S. you are breaking all .NET conventions by using lowecase names for public members.