0 Replies - 1393 Views - Last Post: 29 December 2009 - 09:58 PM

#1 coden4fun  Icon User is offline

  • if(coden4fun.NotTired){ ContinueToCode(); }
  • member icon

Reputation: 28
  • View blog
  • Posts: 696
  • Joined: 27-February 09

List links from a database if there Active

Posted 29 December 2009 - 09:58 PM

Description: For ASP.Net MVC coders. Create a repository data model from your database. Make sure you have an isActive bit somewhere in your table of your database, so you can have (ready to go content, and still working on content) only the ready to go content will be set to the live site, and will have their links set in the navigation; otherwise, it won't even show up.

Using a geeric list, and a repository, create a generic list of links and if they're active (ready for the live site) then they will show up on the navigation.
//First in C# where you create the controller action method 
//to create the method that will populate all content details
//add the following code
public ActionResult Details(int id)
        {
            var repositoryList = _repository.List();
            ViewData["List"] = repositoryList;
            return View(_repository.Get(id));
        }


<!--now is ASP.net add the following in your navigation panel->
 <ul>
     <% foreach (var item in (List<Service>)ViewData["List"])
       {%>
            <% if ((item.isActive) || (item.id != 0)) 
                   { %><li><%=Html.ActionLink(item.Title, "Details", new { id = item.id })%></li><%} %>
       <%} %>
    </ul>


Is This A Good Question/Topic? 0
  • +

Page 1 of 1