开发者

MVC Get data from multiple tables in database for specific user

I'm new to MVC, currently running MVC 2, done a lot av regular ASP.Net in the past.

Background

Have a database containing all the tables for the .Net Membership provider.

Created a table called "Lists" containing UserID, ListID, ListName and so on.

It has a relationship key to the .Net Membership User, UserID column.

There is also a "List_Items" table that has ListID, ItemID, ItemName and so on.

What I have done I managed to create a Entity Data Model mapping to the database. It contains both tables.

In the view I have done this:

<ul>
 <% foreach (var item in Model) { %>
   <li><a href="#<%= Html.Encode(item.ListID) %>"><%= Html.Encode(item.ListName) %></a></li>
 <% } %>
</ul>

In the controller I have done this:

private ToDoDBEntities _db = new ToDoDBEntities();
return View(_db.Todo_Lists.ToList());

This I got from the asp.net/mvc tutorials. This tells me to things... I get all the Lists for all users. And I don't get the List Items from the other table.

What I want to do I want to be able to pass the Provider Userkey to the database, for the logged on user, so I only get's his/hers lists.

I also would like to get Lists table and List Items table to the v开发者_运维百科iew in the same call so I can build the UL/IL with the List. And build content divs with the List Items.

Happy for any input.

/K


What tutorial are you using? Because I highly recommend http://www.asp.net/mvc as a learning resource, follow the tutorials and it will show you how to do what you want. It will also teach you techniques that will make life easier for you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜