Starting with MVC2, messing around with a simple db and just using the index view to display the items like:
in the controller:
//
// GET: /Equipment/
public ActionResult Index()
{
return View(database.Artists.ToList());
}
then the auto generated code in the view:
<td> <%: item.ArtistID %> </td>
<td> <%: item.GenreID %> </td>
etc etc
In my example, its potential that this data hasn't been filled up, so it may be null. Now when I tried to load the view I will get a NullReferenceException. So where would the code for this belong ?
I guess you could have an if statement in the view, though surely this is not where the logic should go. Should I create a html helper which just returns empty string if the value is null?
edit:
Thanks for the help.
I have another query. What if say I'm developing a index browse type page. At the moment im displaying all items on the one page but there are like 2k items. Is there a tutorial or example of how to split this up? I guess my index browse controller could just take a integer range value from the browser, then I just say display next 100