Can anyone tell me how to use ASP.NET MVC 2 without data models...i mean i have sql database and stored procedure which has employyes table i wanna show all employees list on a View without using any data model.
A:
You can have your controller do the sql query, generate a List of something, then pass the list to the view using ViewData. This however is a deformation of the MVC model...
Palantir
2010-07-07 08:17:44
Agree that is controller view only.
airmanx86
2010-07-07 14:45:22
@airmanx68: here on StackOverflow, to express agreement you should upvote the answer you find helpful
Palantir
2010-07-07 15:02:13
+1
A:
I see two solutions.. one is ugly, but it's probably what your'e looking for. In your controller you can use your procedure to get data, and then pass it to the view using ViewData collection, f.e:
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 better solution is to create at least an ViewModel, just to hold the informations you need to display. You can rewrite all data you get from DB to that model. Then you will get very important feature which is strongly typed view.
ŁukaszW.pl
2010-07-07 08:21:42