I have an ASP.NET MVC view, which is there only for testing and diagnosis purposes. Once a while I pass a completely different object (model) to it, and render its properties to see the state of the object. However, this needs the view to be modified for each object.
How can I create an object dumper view? By object dumper view, I mean a view which doesn't need to be changed in any way, on change of its related model. For example, on passing a user
object, or a product
object, or anything else, the view remain untouched, while still functioning correctly.
return View(user);
return View(product);
return View(googleAnalyticsFeed);
Use the ObjectInfo helper to display the type and the value of each object you pass to it. You can use it to view the value of variables and objects in your code, plus you can see data type information about the object.
@ObjectInfo.Print(Model)
Use DisplayForModel() to output a generic view or use display templates for your known objects as noted here: ASP.NET MVC 3: Output specific view for concrete implementation
This way you can customize the output if you need to as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With