Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I have some plain Views, they don't have any logic behind them (there is no action or controller behind them), their only propouse is to alert the user about something like "We have sent you an email to confirm your account", "You have no access to this resource", etc...

These views are really simple, and calling them through a Controller/Action seems to be too much overhead, but somehow I feel like it is not quite correct. What do you think? How do you handle this kind of situations??

I guess this question will apply to any MVC Framework, but in my case I'm using the ASP.NET MVC 3 framework.

share|improve this question
1  
Controller can control multiple views. –  Marjan Venema Jun 2 '12 at 9:03
add comment

3 Answers

up vote 4 down vote accepted

In my 'view' everything needs to go through the controller. When you break the design pattern, even for something simple, you're asking for chaos as the app evolves over time. Ask anyone who's still having to work on 10-12 year old apps where a 'simple' change in 2002 is now a nightmare to deal with in 2012.

In .NET MVC3 you can use partial views to handle some informational widgets as well as JQuery. Which to use will depend on where you want to separate server and client side interaction.

To take it further, you might want to use an Alert view model and have your view (or partial) adjust accordingly. For example, I use a LinkSelectList viewmodel to hold values for a list of links matching search criteria. I use this in several places in an app where the user can search for different items.

share|improve this answer
add comment

But your controller must first find out if those messages are valid.

"We have sent you an email to confirm your account" makes only sense, if an email was sent without errors.

"You have no access to this resource" is something the view can't and should not know. It needs to ask the controller to send the resource. Even the controller should know nothing about access permissions, but has to ask the model. Only after the model found this out, i can respond either with the resource or the error message.

share|improve this answer
add comment

They do have logic "behind" them.

They only came up as the result of certain actions, like "Done, email me and send me a confirmation." As that email action is being done in a controller, the controller then directs to the final view.

If you just want pop-ups for acknowledgment messages, like the ones that appear and then disappear automatically, that's different and you can use Javascript and libraries like jQuery for that.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.