Resolving an Error

What the error said? It because null, right? Null value in dropdown list actually.

Remember on the previous project that we have to populate view bag regularly? We need to do it again.

However, we want to query from Genre table using LINQ.

private void PreparePublisher(SongModel model)
{
    model.Genres = context.Genres.AsQueryable<Genre>().Select(x =>
            new SelectListItem()
            {
                Text = x.Name,
                Value = x.Id.ToString()
            });
}

Finnaly, call the function on Create ActionResult.

public ActionResult Create()
{
    SongModel model = new SongModel();
    PreparePublisher(model);
    return View(model);
}

results matching ""

    No results matching ""