Dropping an Object in an ASP.NET MVC View - Viewing an Object Dumper

I have an ASP.NET MVC view that exists only for testing and diagnostic purposes. After some time, I give it a completely different object (model) and visualize its properties to see the state of the object. However, this requires that the view be changed for each object.

How to create an object dumper view? For an object-oriented view, I mean a view that does not need to be changed in any way, to change its associated model. For example, when passing a user object or a product object or anything else, the view remains intact, but it still functions correctly.

 return View(user); return View(product); return View(googleAnalyticsFeed); 
+4
source share
3 answers

Use the ObjectInfo helper to display the type and value of each object that it passes. You can use it to view the values โ€‹โ€‹of variables and objects in your code, and you can also see information about the type of data about the object.

 @ObjectInfo.Print(Model) 
+11
source

Use DisplayForModel () to display a general view, or use display templates for your known objects, as indicated here: ASP.NET MVC 3: Output a specific view for a specific implementation

This way you can customize the output if you need it too.

+2
source

Since this is your testing, View will suggest using ViewBag, which uses the C # 4.0 dynamic function. Before returning view (); save modal in Viewbag and use viewbag to render data on View.

Edit Assuming View is just a Index view then we can easily run for each loop loop by casting ViewBag as IQuerable

-2
source

Source: https://habr.com/ru/post/1379837/


All Articles