ASP.NET MVC 2 without querying a data model

Can someone tell me how to use ASP.NET MVC 2 without data models ... I mean that I have a sql database and a stored procedure that has a busy table, I want to show a list of all employees in presentation without using any data model.

+4
source share
2 answers

You can force your controller to execute an SQL query, generate a list of something, and then pass the list to the view using ViewData. This, however, is a deformation of the MVC model ...

+1
source

I see two solutions: one is ugly, but this is probably what you are looking for. In your controller, you can use your procedure to receive data, and then pass it to the view using the ViewData collection, fe:

public ActionResult Details(int id) { var intData = SPGetInt(id); var stringData = SPGetString(id); ViewData["intData"] = intData; ViewData["stringData"] = stringData; return View(); } 

and then use it like:

  <%=ViewData["intData"] %> 

The best solution is to create at least a ViewModel just to save the information needed for display. You can rewrite all the data that you get from the database into this model. Then you get a very important feature that is strongly typed.

+1
source

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


All Articles