It was a crowded day , more than that it was a hartal day; so there was only few buses expected to operate. After waiting for 2 hrs I got the bus that I was waiting for, it was the only bus that is to go to Vagaman, hill station located in Kottayam- Idukki border of Kerala, India.I was the first guy to get in the bus that was clear empty as a class room on a extra class day in College. I rushed to a window seat so that I can see all the colors dazzling through. When the bus was about to take two young chaps rushed inside bus, I was pretty sure that he was not mallu’s. The only seat that was now empty was the seat next to me. He approached to my seat. I asked him to where are up to. He was also heading to Vagaman. He was a software professional and to my surprise he was also a web application developer same as me, but different framework. He told me he uses ASP.NET MVC for developing his applications. It was the first time I heard the name ASP.NET MVC. The thought that came to my mind first was why should I need MVC, when I can develop application on plain ASP.NET, and to my anxiety I asked him that. To my surprise he told :
You should NOT use ASP.NET MVC if. . .
• You aren’t willing to build on top of the framework
• You rely on 3rd party vendor controls for lots of the UI
• You are not willing to use open-source libraries
Also in order to maintain state in an ASP.NET web forms application, ASP.NET uses encoded data in a hidden form field via a feature called viewstate. Viewstate does pretty well at providing the illusion of a stateful application, but there are times when problems are encountered. For example, in large applications, viewstate can become very large. Large viewstate not only increases your payload across the network, but it can also impact your search engine ranking by pushing readable page content far down in the rendered code. The control over HTML enables developers to build Ajax applications more comfortably, and it adds more interactivity and responsiveness to existing apps. Direct control over HTML also means better accessibility for implementing something that is in accordance with evolving Web standards. In addition, ASP.NET MVC uses interface-based contracts, which allow components to be more easily tested in isolation. As a result, cleaner and more testable code is often promoted as a good reason to embrace ASP.NET MVC. The runtime environment is the same for ASP.NET Web Forms and ASP.NET MVC applications. The view engine can be asp view engine or a razor.
Rob Conerey (Microsoft employee at the ASP.NET MVC team and creator of SubSonic ) explains why developers should learn mvc after observing questions raised in the community.
In his introduction he starts off by describing WebForms as “The Great Lie”:
WebForms is a lie. It’s abstraction wrapped in deception covered in lie sauce presented on a plate full of diversion and sleight of hand. Nothing you do with WebForms has anything to do with the web – you let it do the work for you.
Rob lists 7 reasons for using ASP.NET MVC or in his own words “7 Reasons To Stop Calling Me A Jerk”:
• Control over HTML
• It Makes You Think
• Learning New Concepts
• It’s Fun
And concludes with:
Bottom line: I’m having fun web programming again and I think that’s pretty motivating, at least for me and my cats. Yet Another Comparison, sure, but hopefully a bit more direct. You have absolutely no reason at all to not learn MVC – but I will concede there may be a reason or two for you to stick with WebForms.
I know many people might think I’m speaking for the rest of Microsoft – hardly. I’m biased and, more importantly, I actually still have my very own brain which forms its own thoughts! I love MVC and I think you will too – just please, please try it before you form an opinion.
It is said that Microsoft initially created ASP.NET MVC (in roughly 2007-08) as a proof of concept to demonstrate that it was possible to apply patterns such as Model-View-Controller (MVC) to ASP.NET. (The MVC pattern, which is frequently used in the design of web sites, aims to separate data, business logic, and the presentation to the user. The challenge in many cases is keeping business logic out of the presentation layer. However, no IT manager will spend money on new software solely because it applies patterns.
He told me lets go in detail:
By default, when starting a new MVC project, Visual Studio offer to create a new Unit Test project based on Microsoft’s Unit Test framework. Other Unit tests framework can also be configured to be used by default instead of Microsoft’s solution. The ASP.NET MVC framework includes a flexible URL routing system that enables you to define URL mapping rules within your applications. The routing system has two main purposes:
• Map incoming URLs to the application and route them so that the right Controller and Action method,
• Construct outgoing URLs that can be used to call back to Controllers/Actions (for example: form posts,links, and AJAX calls) Having the ability to use URL mapping rules to handle both incoming and outgoing URL scenarios adds a lot of flexibility to application code.
I became so fascinated about this new approach, I asked him to tell more about its architecture, he continued:
MVC is a framework for building web applications using a MVC (Model View Controller) design:
• The Model represents the application core (for instance a list of database records).
• The View displays the data (the database records).
• The Controller handles the input (to the database records).
The MVC model defines web applications with 3 logic layers:
The business layer (Model logic)
The display layer (View logic)
The input control (Controller logic)
• The Model is the part of the application that handles the logic for the application data.
Often model objects retrieve data (and store data) from a database.
• The View is the parts of the application that handles the display of the data.
Most often the views are created from the model data.
• The Controller is the part of the application that handle user interaction.
Typically controllers read data from a view, control user input, and send input data to the model.
This code project link is very good for new chaps like you. Also this official asp.net site also is not bad to start with.
I enquired him where I could get MVC installable’s, he told : Its simple download it from here .
Suddenly the conductor asked us whether we took tickets, irony is that it pasted 2 hrs till we started our journey. We took our tickets. He asked the conductor at what time bus will reach wagamon, to my surprise he asked this in malayalam, our local language. He told me he knows many languages like the MVC application that can be localized easily. Then I asked him how localization done in ASP.NET MVC. He began:
Creating a multilingual website is not an easy task, but it will certainly allow your site to reach more audience. Fortunately, the .NET Framework already has components that support different languages and cultures. The format for the culture name is “-“, where is the language code and is the subculture code. Examples include es-CL for Spanish (Chile) and en-US for English (United States). Every thread in .NET has CurrentCulture and CurrentUICulture objects. The UICulture determines which resources are to be loaded for the page by the ResourceManager. The ResourceManager simply looks up culture-specific resources that is determined by CurrentUICulture. In order to create different views for every culture, we will append the culture name to the name of the view. For example, Index.cshtml (the default view), Index.es-CL.cshtml (Spanish, Chile), Index.ar-JO.cshtml (Arabic, Jordan). The view name that has no ending is considered the default culture. A default culture view will be rendered if the requested culture name is not implemented explicitly.Some people prefer to use a single view for all languages because it is more maintainable. While others think replacing views content with code like “@Resources.Something” might clutter the views and will become unreadable.
To my doubt I asked him how do we determine which version of a view to return to the end user? He told:
There is a header field called “Accept-Language” that the browser sends on every request. This field contains a list of culture names (language-country) that the user has configured in their browser. The problem is that this culture may not reflect the real user’s preferred language, such as a computer in a cybercafé. We should allow the user to choose a language explicitly and allow them even to change it. In order to do this sort of things, we need to store the user’s preferred language in a store, which can be perfectly a cookie. We will create a base controller that inspects the cookie contents first, if there is no cookie, we will use the “Accept-Language” field sent by their browser. The base controller checks if the cookie exists, and sets the current thread culture to that cookie value. Of course, because cookie content can be manipulated on the client side, we should always validate its value using a helper class called “CultureHelper”. If the culture name is not valid, the helper class returns the default culture. After that, when we call “Return” in controller action methods, the view name is modified by the base controller behind the scenes to reflect the correct culture in cookie or header field. This way we make sure that the user gets the right content based on their culture.
For client-side, we should worry mainly about numbers, date and time, and messages since these change from culture to culture. There are many ways to implement client-side localization. But here are two common options:
I asked him to summarize this, he smiled and told:
• Add a base controller from which all controllers inherit. This controller will intercept the view names returned and will adjust them depending on the current culture set.
• Add a helper class that stores the list of culture names that the site will support.
• Create a single view or set of views for every culture and language.
• Create resource files that contain translation of all string messages. (e.g. Resources.resx, Resources.es-CL.resx, Resources.ar-JO.resx, etc )