Are you looking for an affordable hosting service? Are you looking for good service at affordable prices? Try HostForLife.eu, only with € 3.00/month, you can get a reasonable price with best service. This topic contains only brief information about ASP.NET MVC, if you want to be more familiar with ASP.NET MVC, you should try HostForLife.eu.
Introduction
Overall, ASP.NET is one of the most popular web application frameworks along with PHP, Java and others. However, the classic ASP.NET WebForms style of application development also has its limitations. For instance, cleanly separating the user interface from the application logic and database access can be a challenge in WebForms applications. Thus, Microsoft created ASP.NET MVC. MVC stands for Model View Controller.
The ASP.NET MVC technology has already been introduced earlier (see the Resources section at the end of this article), and thus this article focuses on the new and improved features planned for .NET Framework version 4.0 that should become available in Spring, 2010. Originally Microsoft announced Visual Studio 2010 would launch on March 22nd, 2010, but most recent announcements indicate delays. As far as version numbers are concerned, the next version of ASP.NET MVC will be assigned the version number 2.0. In this article, you will learn what's new and improved in the newest Release Candidate (RC) version of ASP.NET MVC 2. At the time of this writing (late December, 2009) the latest beta version of Visual Studio 2010 is Beta 2, and it doesn't yet come with the ASP.NET MVC 2 RC. The unfortunate thing is that if you are using Visual Studio 2010 Beta 2, you cannot yet test MVC 2 RC with that version (you can naturally continue to use the older Beta 2 version). Instead, you must test the MVC 2 RC on Visual Studio 2008 SP1.
Of course, the final versions of ASP.NET MVC 2 are planned to work with both Visual Studio 2008 and 2010, so the current is only an interim situation.
Exploring the New Features
ASP.NET MVC 2 is an evolutional update to the framework. The basic features of the original version 1.0 are intact, but new features make development easier and result in cleaner code. The following list summarizes the key new features:
1. Area support and multi-project routing
2. Improved syntax for handling posts (form submits) in controllers
3. HtmlHelper object improvements
4. Attribute support for field validation in models
5. Globalization of validation messages
6. Field templates with custom user controls, and more.
Let's walk through each of these in more detail, starting from the top. In MVC 1.0, each view page was thought of as being a separate unit, and served to the browser as a single unit, possibly combined with a master page. However, if you wanted to combine, say, two views into a single page, you either had to manually render one of the pages or create a user control (.ascx) from one of the views, and then use that control inside the main view page. Although user controls are a fine solution, they break out of the MVC pattern.
In MVC 2, you can utilize so-called areas to solve the problem. With area support, you can combine different view pages into a single, larger view similar to the way you can build master pages (.master) and designate parts of them to be filled with content at run-time. It is possible to combine areas into views both inside a single MVC web project ("intra-project areas"), or combine areas in different projects into views ("inter-project areas"), accessible through direct URLs in the same scope.project ("intra-project areas"), or combine areas in different projects into views ("inter-project areas"), accessible through direct URLs in the same scope.
The following paragraphs walk you through using areas inside a single project. If you wanted to combine multiple MVC web projects into a single larger application, you would need to manually edit the .csproj project files of each project part of the overall solution (the edits you need to do are documented in the .csproj XML comments), add proper project references from the child projects to the master project, and then register routes using the MapAreaRoute method of the Routes object in the Global.asax file. In this article, focus is on single-project area support.
To get started with the areas, right-click your project's main node in Solution Explorer, and select the Add/Area command from the popup menu. This will open a dialog box asking for the name of your new area. Unlike with controller names, you don't need to append the word "Area" to the name, but you can if you prefer. However, bear in mind that intra-project areas will be accessed using the default route of /areaname/controllername/action/id. Because of this, you might not want to suffix the word "Area". In this article however, the word "Area" is appended for clarity.
Once you have created your area, Visual Studio will add a new folder called "Areas" in your project. This folder will contain a sub-folder with the name of your area, and inside that you will see a familiar layout of folders for controllers, views and models. In fact, you would add controllers, views and models to this area folder just the same as you would add them to your "master" MVC project. All in all, an area is like a mini MVC application inside another. Note also the AreaRegistration.cs code file. This file's definitions are referenced to from the Global.asax.cs file.
Areas can be used in multiple ways. Because they are directly accessible using the previously mentioned default route, you can utilize them like any other link inside your application. Or, if you had an area controller action that would return a snippet of HTML code to be used inside a larger HTML page (a normal view page), you could use the HtmlHelper.RenderAction as follows:
<% Html.RenderAction("NetworkStatus", "Application", new { Area = "StatusArea" }); %>
Notice how there's an anonymous object being used to specify which area you want to use. Because areas can be completely independent of the master project, you can easily create usable parts or building blocks from your MVC applications and then combine them into larger solutions.
Area support is a very welcome addition to the framework. Luckily to us developers, area support is by no means the only new feature in ASP.NET MVC 2, like the next sections show.
Handling posts and encoding
When you need to handle form posts in your MVC applications, you generally write a new, overloaded controller action method to process the submitted data, and store it for example in a database. Since you only want these methods to be called using the HTTP protocol POST verb, you add an attribute at the beginning of the method like this:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult MyAction(MyObject data)
...
Although there's nothing wrong in the AcceptVerbs attribute, ASP.NET MVC 2 allows you to achieve the same thing with a shorter attribute declaration:
[HttpPost]
public ActionResult MyAction(MyObject data)
...
Even though this is a small improvement, it is very likely that all MVC developers give it a warm welcome. Another useful new improvement is the support for automatically encoded output tags in view pages. Strictly speaking, this is not a new ASP.NET MVC feature, but instead a feature in ASP.NET 4.0. Even so, this new tag type is especially useful in MVC applications.
To illustrate the new tag, consider the following very common need to encode output for HTML:
<%= Model.CustomerName %>
This is a very simple tag, and works well in many situations. However, if the customer name were to contain certain special characters, you would need to encode the output to avoid user interface mess-ups and cross-site scripting attacks. A straightforward MVC method would do the trick:
<%= Html.Encode(Model.CustomerName) %>
All these ways to encode output are not inconvenient, but a shorter syntax would be great. This is what the nifty new “code block” tag does:
<%= Model.CustomerName %>
Notice the colon (:) immediately after the opening tag. It is a new way to encode output. The old equal sign syntax (which itself is a shortcut for Response.Write) is not going away. You can continue to use the old way, but the colon-syntax encoding is there to make the view page syntax cleaner.
Note that at this writing, you cannot use ASP.NET MVC 2 RC within Visual Studio 2010 Beta 2. Thus, you cannot effectively use this combination to test these code block tags, but you can test them in regular ASP.NET 4.0 applications (or with the older MVC Beta 2).
Using lamda expressions with the HtmlHelper object
If you have used ASP.NET MVC 1.0, then you've most probably also created a model object and enabled editing of its details with HTML code similar to the following:
<%= Html.TextBox(“Name”, Model.Name) %>
Although this is fine for many purposes, the problem is that you still have to enter a string constant. Because it is a string, the compiler will not complain if you later change the property name in the model class, but forget to change the HTML tag. Also, the syntax is somewhat verbose (at least to some developers), and requires you to manually create one field per model object property.
In ASP.NET MVC 2, you can use the new TextBoxFor method. Just like the previous HtmlHelper methods like Label, ListBox, and so on, there are now multiple *For methods that all accept a lambda expression returning the correct object value.
Thus, to create a new editing control for the Name property, you could write code like this:
<%= Html.TextBoxFor(c => c.Name %>
Here, the lambda expression parameter "c" is replaced at runtime with the model object instance, and in addition to getting rid of the string value, you will get full IntelliSense support just like before with the model object.
ASP.NET MVC 2 also brings support for a convenient way to create editing forms for complex objects quickly. For instance, if you had a model object with three fields, you could either manually create labels and text boxes for each of the three fields, or use a new extension method called EditorForModel. This method will create form fields for each visible property in the model:
<%= Html.EditorForModel() %>
This method is really convenient, if you don't have special formatting requirements for your editing forms.
Top Reasons to host your ASP.NET MVC Website with HostForLife.eu
There are many reasons why so many people choose HostForLife over any other web hosting provider each year. Whether you’re beginner or an experience webmaster, HostForLife offers the perfect solution for everyone.
You’ll have highly trained, skilled professional technical support people ready, willing, and wanting to help you 24 hours a day. Your web hosting account servers are monitored from three monitoring points, with two alert points, every minute, 24 hours a day, 7 days a week, 365 days a year. The followings are the list of other added-benefits you can find when hosting with us:
1. World-class 24x7 Customer Support
Will your hosting company promptly answer questions and resolve issues - at 3 am on a Sunday? Even some providers claiming “24x7” support will not - but HostForLife will. Our outstanding uptime is backed by true 24x7 customer support. An expertly trained technician will respond to your query within one hour, round the clock. You will also get qualified answers. Other hosting companies typically have very low - level support staff during the night or weekends. HostForLife always has knowledgeable, top - level support standing by, day or night, to give you the answers you need.
2. Commitment to Outstanding Reliability
Reliability, Stability, and Performance of our servers remain out TOP priority. Even our basic service plans are equipped with standard service level agreements for 99.99% uptime. Advanced options raise the bar to 99.99%. Our state-of-the-art data centers combine servers and SAN storage with full redundancy and operational tools with proprietary service management techniques. Full backup and recovery capabilities are implemented, including redundant power supplies, cooling and connectionsto major data networks.
3. “Right-size” plans for maximum value
HostForLife offers a complete menu of services. IT professionals select only what they need - and leave behind what they don’t. The result is an optimal blend of cost and performance. We offer IT professionals more advanced features and the latest technology - ahead of other hosting companies.
4. Profitable, Stable, Debt-free Business
Financial stability is the bedrock of a hosting provider’s ability to deliver outstanding uptime, cost-effective service plans and world-class 24x7 support. HostForLife’s customers are assured of our financial integrity and stability - a stark contrast to the ups and downs they may have experienced with other providers.
5. The Best Account Management Tools
HostForLife revolutionized hosting with Plesk Control Panel, a Web-based interfaces that provides customers with 24x7 access to their server and site configuration tools. Some other hosting providers manually execute configuration requests, which can take days. Plesk completes requests in second. It is included free with each hosting account. Renowned for its comprehensive functionally - beyond other hosting control panels - and ease of use, Plesk Control Panel is available only to HostForLife’s customers.
6. 30-Day Money Back Guarantee
HostForLife 30 day money back guarantee ensures you have the ability to cancel your account anytime within your first 30 days under our full 30 day money back guarantee (less one-time account setup free). So what are you waiting for? Sign up today, risk free…
7. Simplicity with FREE 1-Click Installation
HostForLife was designed with ease of use in mind. From one click installations of your favourite website applications to our much talked about drag and drop website builder, you can rest assure your stay with us is going to be a smooth one. HostForLife offers the most extensive set of scripts on the web allowing you to build complicated websites with little or no programming knowledge at all. From blogs to forums to powerful e-commerce solutions, Super Green has something that is right for you.