4

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.

1
  • 1
    why are you voting to close? you may not like the question or the fact that he is trying to force the MVC model, but other than that it's a programming question... Commented Jul 7, 2010 at 8:18

2 Answers 2

2

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...

Sign up to request clarification or add additional context in comments.

2 Comments

Agree that is controller view only.
@airmanx68: here on StackOverflow, to express agreement you should upvote the answer you find helpful
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.