tags:

views:

89

answers:

1

Imagine the scenario you have a listing page that is a concatenation of multiple entities on your site (such as a search page).. you collate all the entities of your site in the action, and map all of them into a generic view model type..

pseudo:

from articles, posts, projects
orderby rating
select top 50 as 'SearchResult'

My search result class might look like this:

SearchResult { Title, Snippet, Rating }

In this scenario, the view will have no context of what each result 'is', so how can it generate a url to get more details, should the result then be categorized?

SearchResult { Title, Snippet, Rating, ResultType }
where ResultType is { Article, Post, Project } enum

This would work, it would require the view to discover the relation of the enum to a controller action..

This would however cause problems for maintainability, each new entity type or static content section would need to be categorized, and a mapping from that new category to a controller action.. additionally this causes problems because.. what data do I pass to the action? what if there isn't any data to pass?

Seems like the best scenario would be to generate the 'more details' url in the action, where it has context of each entity, and the action / data mapping..

Is it ok for controllers/actions to generate urls, shouldn't they stay agnostic?

Thanks in advance.

+3  A: 

I think passing URLs from controller to view is OK. For exampe, if you develop a Web search engine (new Google competitor :) ) there is no other way for view to determine where a document with given title, snippet and rating was found.

Alexander Prokofyev
+ Totally agree
eu-ge-ne