In this article, we will discuss new features ASP.NET MVC and also the examples. ASP.NET MVC 2 builds on ASP.NET MVC 1.0. MVC 2 can be used with asp.net 3.5 SP1 and With ASP.NET 4.O. MVC 2 by default installed on your computer when you install Visual Studio 2010.
The new features of ASP.NET MVC 2:
1. Template Helper to use Lambda Expression
2. Asynchronous Controllers for parallel long running tasks and enable to Asynchronous Operations Matter
3. Area to split large project to avoid the complexity of the large project. Right Click on your Project in the Solution Explorer, click Add and then click Area. Now you can add forum or admin in the Area
4. Strongly Typed UI Helpers to view model level error instead of all validation Errors.
5. HiddenInputAttribute Class for Templated Helpers when DisplayValue is false nothing will be happen but when DisplayValue is true then input hidden element will be rendered when displaying model in editor template
6. Enhancements to ModelBinders
7. Automatic HTML-Encoding
8. Enhancements to ModelBinders supports are:
- Increasing Security with HTTPS
- Avoiding the JSON Array Attack
- Short Notation for AcceptVerbs Attribute
- Overriding the HTTP Verb
- Binary Binding
- Ability to render subsections of site pages
Example
Open your Visual Studio 2010. Create New Project, window will be display on your screen, by default .Net Framework 4 is selected. Expand Visual C# and click on Web. Select ASP.NET MVC 2 Web Application
If you want to create Unit Test then select Yes option and give the Test Project name. By default name of the test project is the application project MvcApplication.Tests. You can change the name of project as shown in below figure.
Project is created as you see in the below Figure. Content folder includes CSS file, Script contains js Files. You have three main folders Controller, Models and Views.
Below is the Simple HomeController class.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace MvcApplication.Controllers
{
[HandleError]
public class HomeController : Controller
{
public ActionResult Index()
{
ViewData["Message"] = "This is my First MVC Web Project";
return View();
}
public ActionResult About()
{
return View();
}
}
}
Here is the Code of index.aspx Page
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2><%: ViewData["Message"] %></h2>
<p>
To learn more about ASP.NET
MVC visit <a href="http://asp.net/mvc" title="ASP.NET MVC
Website">http://asp.net/mvc</a>.
</p>
</asp:Content>
To learn more about ASP.NET MVC visit <a href="http://asp.net/mvc"
title="ASP.NET MVC Website">http://asp.net/mvc</a>.
</p>
</asp:Content
Default created MVcApplication class in Global.aspx.cs file as shown in below code.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
namespace MvcApplication
{
// Note: For instructions on enabling IIS6 or IIS7 classic mode,
// visit http://go.microsoft.com/?LinkId=9394801
//Author:Aamir Hasan
public class MvcApplication : System.Web.HttpApplication
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
// Parameter defaults
);
}
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterRoutes(RouteTable.Routes);
}
}
}
What is so SPECIAL on ASPHostDirectory.com .NET MVC Hosting?
We know that finding a cheap, reliable web host is not a simple task so we’ve put all the information you need in one place to help you make your decision. At ASPHostDirectory, we pride ourselves in our commitment to our customers and want to make sure they have all the details they need before making that big decision.
We will work tirelessly to provide a refreshing and friendly level of customer service. We believe in creativity, innovation, and a competitive spirit in all that we do. We are sound, honest company who feels that business is more than just the bottom line. We consider every business opportunity a chance to engage and interact with our customers and our community. Neither our clients nor our employees are a commodity. They are part of our family.
The followings are the top 10 reasons you should trust your online business and hosting needs to us:
- FREE domain for Life - ASPHostDirectory gives you your own free domain name for life with our Professional Hosting Plan and 3 free domains with any of Reseller Hosting Plan! There’s no need to panic about renewing your domain as ASPHostDirectory will automatically do this for you to ensure you never lose the all important identity of your site
- 99,9% Uptime Guarantee - ASPHostDirectory promises it’s customers 99.9% network uptime! We are so concerned about uptime that we set up our own company to monitor people’s uptime for them called ASPHostDirectory Uptime
- 24/7-based Support - We never fall asleep and we run a service that is opening 24/7 a year. Even everyone is on holiday during Easter or Christmast/New Year, we are always behind our desk serving our customers
- Customer Tailored Support - if you compare our hosting plans to others you will see that we are offering a much better deal in every aspect; performance, disk quotas, bandwidth allocation, databases, security, control panel features, e-mail services, real-time stats, and service
- Money Back Guarantee - ASPHostDirectory offers a ‘no questions asked’ money back guarantee with all our plans for any cancellations made within the first 30 days of ordering. Our cancellation policy is very simple - if you cancel your account within 30 days of first signing up we will provide you with a full refund
- Experts in .Net MVC Hosting - Given the scale of our environment, we have recruited and developed some of the best talent in the hosting technology that you are using. Our team is strong because of the experience and talents of the individuals who make up ASPHostDirectory
- Daily Backup Service - We realise that your website is very important to your business and hence, we never ever forget to create a daily backup. Your database and website are backup every night into a permanent remote tape drive to ensure that they are always safe and secure. The backup is always ready and available anytime you need it
- Easy Site Administration - With our powerful control panel, you can always administer most of your site features easily without even needing to contact for our Support Team. Additionally, you can also install more than 100 FREE applications directly via our Control Panel in 1 minute!
Happy Hosting!