tags:

views:

69

answers:

2

Maybe I'm complicating this but you will enlight me for sure.

Imagine a page where a list is displayed. That list is paged. I specify the list displays 30 items, therefore the controller returns my 30 items and the view renders the 30 items. My question is: both the controller and the view need to know the 30 setting. Where should it be stored? Web.config? I'm thinking if sharing configs via web.config that are used across "layers" is a good practice...

Tks in advance

A: 

Web.config is fine. Have you considered allowing the page length to be dynamic, perhaps based on a querystring value? (either way, you'll still need a default stored or hard-coded somewhere)

Also, I'm probably parsing words here, but you don't want your view to explicitly know of this setting (ie, accessing the web.config value directly). It should just iterate the list of items that the controller passes it, regardless of quantity.

Kurt Schindler
Agreed, and the querystring option is another reason why the view shouldn't know where the setting is sourced. All that logic would live in your controller (or, if it got complicated enough, perhaps a model).
krohrbaugh
What I said is not absolutely correct, sorry for this. What I have is a number of columns and rows, say 3 columns per 10 rows, getting the 30 items to retrieve. I need the pair of values in the View so it can be smart enough to generate a proper layout, and I need it in the controller for it to know it needs to fetch 3*10 records. Passing these parameters in the query string is not a good idea because the user could mess with them to break the layout. I guess I'll add them to the web.config. Tks you both for your answers ;)
Dante
I was thinking about this and shouldn't be the correct way to implement:- Controller reads web.config (10 rows per 3 cols parameters);- Controller gets 10x3 elements from the DB;- Controller feeds 30 elements to the view, along with the number of columns and rows it should generate.This would leave the View totally blind regarding the configurations...
Dante
+1  A: 

I don't think what you're describing is violating separation of concerns. By design data is shared across the layers of an MVC application, since the view has to get the data one way or another.

What you shouldn't do is have the view know how to get the data. In other words, your view shouldn't know where that "30" setting is coming from, so that you can change it in the future without changes necessary to the view.

krohrbaugh