I am returning an anonymous Json'ed type:
IList<MyClass> listOfStuff = GetListOfStuff();
return Json(
new {
stuff = listOfStuff
}
);
In some cases, I know what listOfStuffwill be empty. Therefore, I do not want the overhead of the call GetListOfStuff()(which causes the database call).
So in this case, I write:
return Json(
new {
stuff = new List<ListOfStuff>()
}
);
which seems a bit overly detailed. I donβt care what type Listhe is, because he is still empty.
Is there a shorthand notation that can be used to denote an empty enumerated / list / array? Sort of:
return Json(
new {
stuff = new []
}
);
Or have I been programming JavaScript for too long? :)
source
share