-1

I cant seem to get the URL's in a simple list which I can show on a page. I already have the connection with the database in another project within my solution and that works for sure. only problem is putting the data into a list.

URLController

public class URLController : Controller
{      
    public ActionResult List()
    {
        LinkHubDbEntities db = new LinkHubDbEntities();
        ViewBag.UrlList = new SelectList(db.tbl_Url.OrderBy(c => c.UrlId), "UrlTitle", "UrlDesc");

        return View();
    }
}

The view :

@model BOL.tbl_Url

@{
ViewBag.Title = "List";
}

<ul>

@foreach (var UrlId in ViewBag.UrlList)
{
    <li>@tbl_Url.UrlTitle</li>
}

</ul>
mason
  • 31,774
  • 10
  • 77
  • 121
Mike Lammers
  • 171
  • 2
  • 4
  • 14
  • Looks like there are some very basic fundamentals which are wrong – blogbydev Sep 17 '15 at 16:30
  • Okay, I don't like the ViewBag and I don't like a lot of other things but.... intellisense should provide you with @Model.UrlTitle instead of the weird thing you've got at the moment. Try that. If it doesn't work I'll post some code which will work properly and have a better structure. – Rich Bryant Sep 17 '15 at 16:38
  • http://stackoverflow.com/questions/25279547/how-to-display-database-records-in-asp-net-mvc-view do a simple google search come on @MikeLammers – MethodMan Sep 17 '15 at 16:40
  • whats the @tbl_Url inside the for loop? the URLList is in your viewbag and not model. – Kar Sep 17 '15 at 16:45

1 Answers1

0

You might want to do something like this:

Controller Action:

public ActionResult Foo()
        {
            ViewBag.ProcessList = System.Diagnostics.Process.GetProcesses();
            return View();
        }

View:

<ul>
@foreach (var item in ViewBag.ProcessList)
    {
        <li>@item.ProcessName</li>
    }
</ul>
blogbydev
  • 1,445
  • 2
  • 17
  • 29