1

UPDATE My answer

This is my controller:

public class AdminController : Controller
{
    //
    // GET: /Admin/
    public readonly Itopics _adminT;
    public AdminController(Itopics ts)
    {
        _adminT = ts;
    }

    public ActionResult Index()
    {
        return View();
    }

    public ActionResult MakeMenu()
    {

       var model= _adminT.GetMenu();
       return View(model);
    }

The question is how do I iterate over the results in my view.. The model contains List object... any suggestions?

BlackFire27
  • 1,470
  • 5
  • 21
  • 32
  • Is better to keep persistence outside of your model, see this answer http://stackoverflow.com/a/6694195/743965 – wnascimento Feb 25 '12 at 11:22
  • Where do I put all the ado.net logic..in the model..or in the action? – BlackFire27 Feb 25 '12 at 11:36
  • Neither. Know about persistence details is out of the responsibilities of the model and action. You can use a design pattern to put the data access, like Repository, Data Mapper or DAO. – wnascimento Feb 25 '12 at 11:54
  • How can I iterage over the results (mn.mylist) in my view..what header should I add , so that the view will recognize myList?...I am going to modify my logic too. – BlackFire27 Feb 25 '12 at 12:03
  • In your GetMenu method, you can iterate over the SqlDataReader result and build instances of menu, after each instance created, add the instance to myList. Your controller are ok, and in your view the model should be @model List – wnascimento Feb 25 '12 at 12:25
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/8212/discussion-between-wnascimento-and-blackfire27) – wnascimento Feb 25 '12 at 12:26
  • I did all that.. I need to pass the results to the view..but I dontknow how!?!? I need the view to recognize my item (which is a class) and the List..but I dont know how to import them – BlackFire27 Feb 25 '12 at 12:41

1 Answers1

0

See this article and download the attached code. An nice example, will show you how to build your model from the SqlDataReader result.

http://www.mikesdotnetting.com/Article/132/ASP.NET-MVC-is-not-all-about-Linq-to-SQL

...

See the code from GetList method inside AddressDB class, is is exactly what you need.

wnascimento
  • 1,949
  • 1
  • 19
  • 16