I have a section of my site that requires global data for navigation, now I am doing the following inside the attribute:
ViewData["projects"] = new[]
{
new ProjectNav { Id = 1, Name = "Big project in New York" },
new ProjectNav { Id = 2, Name = "Small project in New Jersey" },
new ProjectNav { Id = 3, Name = "Big project in Florida" },
}
Then I mark up my controller methods as follows:
[ProjectNav]
public ActionResult Index()
{
}
And, in my opinion, I would do something like this:
<% foreach (ProjectNav project in (IEnumerable<ProjectNav>)ViewData["projects"])
{ %>
<% } %>
This works, but is there a way to do this in a more strongly typed way? The only thing I can think of is to create a Dto with ProjectNav material as a member, but then you create a separate Dto for each of the controller methods, and that is definitely NOT DRY. Is there a better way to do this that I'm just missing?
source
share