views:

33

answers:

2

Am I able to use asp:Repeater and Html.ActionLink together for creating a dynamic menu? Or is there any other methods that I can use it?

Note: I'm getting the menu list from SQL.

A: 

I think you can, there are a lot of information on the web about how to use asp controls in MVC code. also, MVC seems to have its own repeater: http://davidhayden.com/blog/dave/archive/2009/04/07/ASPNETMVCControlsASPNETMVCFuturesRepeaterControlExample.aspx

akonsu
+1  A: 

I'm going to assume you are using ASP MVC 1 or 2 if you're using HTML.ActionLink. If that is the case, what you'll want to do is pass your list of items to the view through your Model or ViewModel and in the view, create a for each loop to display the items instead of using a repeater control.

Another option is to create a partial view that you pass your list of menu items to and create the for each loop in there then render the partial where ever you need to show your menu.

if you put the menu in the Master Page it will automatically show up every where.

Justin
oh sorry forgot to say yes I'm using MVC2.
Kaan
I don't want to sound like a jerk or anything but I think it might be considered bad form to use stuff like asp:Repeater controls in MVC applications to the purists. Someone please correct me if I am wrong, but I never saw a lot of it happening in the videos and tutorials I've seen or read.
Justin
Agree with Justin, there is no point to using a repeater in MVC; a foreach loop will be **much** cleaner and easier to read.
Kirk Woll