Questions tagged [model-view-controller]

Model–View–Controller (MVC) is an architectural pattern, introduced in mid 1970-s in PARC into how to compose software interfacing also with user-interactions. For Microsoft ASP.NET MVC, please use [asp.net-mvc] or [asp.net-core-mvc] tag instead. For Spring MVC, please use [spring-mvc] tag instead.

Model–View–Controller (MVC) is an architectural pattern used in software engineering, since Palo Alto Research Centre released one such in mid 1970-ies, designed in Smalltalk-79 language.

The pattern isolates "domain logic" (the application logic for the user) from the user interface (input and presentation), permitting independent development, testing, portability and maintenance of each (separation of concerns).

Image which demonstrates typical collaboration of the MVC components:

MVC

Reference

The analogy

MVC can be metaphorically related to a TV. You have various channels, with different information on them supplied by your cable provider (the model). The TV screen displays these channels to you (the view). You pressing the buttons on the remote controls affects what you see and how you see it (the controller).

33635 questions
60
votes
2 answers

What exactly is the difference between Web API and REST API in MVC?

I have a little understanding on REST API. As per my knowledge it is used to work with HTTP services (GET, POST, PUT, DELETE). When I add a Web API controller it provides me some basic methods like : public class Default1Controller : ApiController …
rohit singh
  • 1,239
  • 3
  • 15
  • 26
60
votes
4 answers

Understanding JSF as a MVC framework

I am reading on JSF and I feel rather confused why JSF is a MVC framework (or atleast which parts belongs to which "letter"). I looked at this question: What components are MVC in JSF MVC framework? I read there if you don't look at it in an…
LuckyLuke
  • 47,771
  • 85
  • 270
  • 434
59
votes
6 answers

Showing alert in angularjs when user leaves a page

I'm an angularjs new bee. I'm trying to write a validation which alerts the user when he tries to close the browser window. I have 2 links on my page v1 and v2.When clicked on the links it takes to the specific pages. Here is the code to redirect to…
iJade
  • 23,144
  • 56
  • 154
  • 243
56
votes
7 answers

ASP.NET MVC Url.Action adds current route values to generated url

I have seen this question a couple of times here in SO but none of them with any acceptable answer: ASP.NET MVC @Url.Action includes current route data ASP.NET MVC implicitly adds route values Basically I have Controller with an action method called…
willvv
  • 8,439
  • 16
  • 66
  • 101
55
votes
4 answers

Best Place for Validation in Model/View/Controller Model?

I am working on a PHP project which makes extensive use of the MVC design pattern. I am looking to add validation to a form and am curious as to what the right place for validation is. Due to the way that forms are generated, validation on postback…
Lea Hayes
  • 62,536
  • 16
  • 62
  • 111
55
votes
24 answers

Strip off specific parameter from URL's querystring

I have some links in a Powerpoint presentation, and for some reason, when those links get clicked, it adds a return parameter to the URL. Well, that return parameter is causing my Joomla site's MVC pattern to get bungled. What's an efficient way to…
tpow
  • 7,600
  • 11
  • 59
  • 84
55
votes
4 answers

MVC [HttpPost/HttpGet] for Action

I am using MVC C#. Can somebody give an example on why one would use [HttpPost/HttpGet] for an Action. How can an active have both - what is the practical use?
Nate Pet
  • 44,246
  • 124
  • 269
  • 414
54
votes
8 answers

What is the right MVC diagram for a web application?

Which MVC diagram is correct? Each have different arrows... Diagram 1 Diagram 2 (source: stannard.net.au) Diagram 3 Diagram 4 (source: sun.com) Diagram 5 (source: shopno-dinga.com)
Marcus
  • 9,011
  • 10
  • 45
  • 65
54
votes
6 answers

How can I get the route name in controller in ASP.NET MVC?

ASP.NET MVC routes have names when mapped: routes.MapRoute( "Debug", // Route name -- how can I use this later???? "debug/{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = string.Empty } ); Is there a way to…
Mike Scott
  • 12,274
  • 8
  • 40
  • 53
54
votes
7 answers

Data Annotation Ranges of Dates

Is it possible to use [Range] annotation for dates? something like [Range(typeof(DateTime), DateTime.MinValue.ToString(), DateTime.Today.ToString())]
Davy
  • 1,043
  • 2
  • 12
  • 21
53
votes
2 answers

Applying MVC With JavaFx

I'm new to the GUI world/OO design pattern and I want to use MVC pattern for my GUI application, I have read a little tutorial about MVC pattern, the Model will contain the data, the View will contain the visual element and the Controller will tie…
KarimS
  • 3,812
  • 9
  • 41
  • 64
53
votes
6 answers

If else statements in .html.erb in views

In rails, I often run into the situation where inside the views I'll do something like <% if @some_condition_previusly_established_in_a_controller %>
123
<% else %>
something else
<% end %> It looks a…
dsp_099
  • 5,801
  • 17
  • 72
  • 128
51
votes
4 answers

Architecture more suitable for web apps than MVC?

I've been learning Zend and its MVC application structure for my new job, and found that working with it just bothered me for reasons I couldn't quite put my finger on. Then during the course of my studies I came across articles such as MVC: No…
GordonM
  • 31,179
  • 15
  • 87
  • 129
51
votes
4 answers

MVC vs. Flux ? Bidirectional vs. Unidirectional?

Looking at the following diagram (which explains MVC), I see unidirectional data flow. So why do we consider MVC to have bidirectional data flow while justifying Flux ?
Arian
  • 7,397
  • 21
  • 89
  • 177
50
votes
10 answers

ASP.NET Core 1.1 runs fine locally but when publishing to Azure says "An error occurred while starting the application."

I've been developing an ASP.NET Core web app, based largely on the MVC template provided in Visual Studio 2017 RC2. It runs just fine in local debug mode, but when I try to publish it to an Azure hosted web app, I get this error: An error occurred…
derf26
  • 862
  • 1
  • 7
  • 16