ASP.NET MVC 3 Hosting :: ASP.NET MVC 3 First Look
Posted
by mbridge
on Geeks with Blogs
See other posts from Geeks with Blogs
or by mbridge
Published on Thu, 23 Dec 2010 01:43:43 GMT
Indexed on
2010/12/23
1:55 UTC
Read the original article
Hit count: 654
Filed under:
MVC 3 View Enhancements
MVC 3 introduces two improvements to the MVC view engine:
- Ability to select the view engine to use. MVC 3 allows you to select from any of your installed view engines from Visual Studio by selecting Add > View (including the newly introduced ASP.NET “Razor” engine”):
- Support for the next ASP.NET “Razor” syntax. The newly previewed Razor syntax is a concise lightweight syntax.
MVC 3 Control Enhancements
- Global Filters: ASP.NET MVC 3 allows you to specify that a filter which applies globally to all Controllers within an app by adding it to the GlobalFilters collection. The RegisterGlobalFilters() method is now included in the default Global.asax class template and so provides a convenient place to do this since is will then be called by the Application_Start() method:
void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleLoggingAttribute());
filters.Add(new HandleErrorAttribute());
}
void Application_Start()
{
RegisterGlobalFilters (GlobalFilters.Filters);
}
- Dynamic ViewModel Property : MVC 3 augments the ViewData API with a new “ViewModel” property on Controller which is of type “dynamic” – and therefore enables you to use the new dynamic language support in C# and VB pass ViewData items using a cleaner syntax than the current dictionary API.
Public ActionResult Index()
{
ViewModel.Message = "Hello World";
return View();
}
- New ActionResult Types : MVC 3 includes three new ActionResult types and helper methods:
1. HttpNotFoundResult – indicates that a resource which was requested by the current URL was not found. HttpNotFoundResult will return a 404 HTTP status code to the calling client.
2. PermanentRedirects – The HttpRedirectResult class contains a new Boolean “Permanent” property which is used to indicate that a permanent redirect should be done. Permanent redirects use a HTTP 301 status code. The Controller class includes three new methods for performing these permanent redirects: RedirectPermanent(), RedirectToRoutePermanent(), andRedirectToActionPermanent(). All of these methods will return an instance of the HttpRedirectResult object with the Permanent property set to true.
3. HttpStatusCodeResult – used for setting an explicit response status code and its associated description.
MVC 3 introduces two improvements to the MVC view engine:
- Ability to select the view engine to use. MVC 3 allows you to select from any of your installed view engines from Visual Studio by selecting Add > View (including the newly introduced ASP.NET “Razor” engine”):
- Support for the next ASP.NET “Razor” syntax. The newly previewed Razor syntax is a concise lightweight syntax.
MVC 3 Control Enhancements
- Global Filters: ASP.NET MVC 3 allows you to specify that a filter which applies globally to all Controllers within an app by adding it to the GlobalFilters collection. The RegisterGlobalFilters() method is now included in the default Global.asax class template and so provides a convenient place to do this since is will then be called by the Application_Start() method:
void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleLoggingAttribute());
filters.Add(new HandleErrorAttribute());
}
void Application_Start()
{
RegisterGlobalFilters (GlobalFilters.Filters);
}
- Dynamic ViewModel Property : MVC 3 augments the ViewData API with a new “ViewModel” property on Controller which is of type “dynamic” – and therefore enables you to use the new dynamic language support in C# and VB pass ViewData items using a cleaner syntax than the current dictionary API.
Public ActionResult Index()
{
ViewModel.Message = "Hello World";
return View();
}
- New ActionResult Types : MVC 3 includes three new ActionResult types and helper methods:
1. HttpNotFoundResult – indicates that a resource which was requested by the current URL was not found. HttpNotFoundResult will return a 404 HTTP status code to the calling client.
2. PermanentRedirects – The HttpRedirectResult class contains a new Boolean “Permanent” property which is used to indicate that a permanent redirect should be done. Permanent redirects use a HTTP 301 status code. The Controller class includes three new methods for performing these permanent redirects: RedirectPermanent(), RedirectToRoutePermanent(), andRedirectToActionPermanent(). All of these methods will return an instance of the HttpRedirectResult object with the Permanent property set to true.
3. HttpStatusCodeResult – used for setting an explicit response status code and its associated description.
MVC 3 AJAX and JavaScript Enhancements
MVC 3 ships with built-in JSON binding support which enables action methods to receive JSON-encoded data and then model-bind it to action method parameters.
For example a jQuery client-side JavaScript could define a “save” event handler which will be invoked when the save button is clicked on the client. The code in the event handler then constructs a client-side JavaScript “product” object with 3 fields with their values retrieved from HTML input elements. Finally, it uses jQuery’s .ajax() method to POST a JSON based request which contains the product to a /theStore/UpdateProduct URL on the server:
$('#save').click(function () {
var product = {
ProdName: $('#Name').val()
Price: $('#Price').val(),
}
MVC 3 ships with built-in JSON binding support which enables action methods to receive JSON-encoded data and then model-bind it to action method parameters.
For example a jQuery client-side JavaScript could define a “save” event handler which will be invoked when the save button is clicked on the client. The code in the event handler then constructs a client-side JavaScript “product” object with 3 fields with their values retrieved from HTML input elements. Finally, it uses jQuery’s .ajax() method to POST a JSON based request which contains the product to a /theStore/UpdateProduct URL on the server:
$('#save').click(function () {
var product = {
ProdName: $('#Name').val()
Price: $('#Price').val(),
}
$.ajax({
url: '/theStore/UpdateProduct',
type: "POST";
data: JSON.stringify(widget),
datatype: "json",
contentType: "application/json; charset=utf-8",
success: function () {
$('#message').html('Saved').fadeIn(),
},
error: function () {
$('#message').html('Error').fadeIn(),
}
});
return false;
});
MVC will allow you to implement the /theStore/UpdateProduct URL on the server by using an action method as below. The UpdateProduct() action method will accept a strongly-typed Product object for a parameter. MVC 3 can now automatically bind an incoming JSON post value to the .NET Product type on the server without having to write any custom binding.
[HttpPost]
public ActionResult UpdateProduct(Product product) {
// save logic here
return null
}
MVC 3 Model Validation Enhancements
MVC 3 builds on the MVC 2 model validation improvements by adding support for several of the new validation features within the System.ComponentModel.DataAnnotations namespace in .NET 4.0:
- Support for the new DataAnnotations metadata attributes like DisplayAttribute.
- Support for the improvements made to the ValidationAttribute class which now supports a new IsValid overload that provides more info on the current validation context, like what object is being validated.
- Support for the new IValidatableObject interface which enables you to perform model-level validation and also provide validation error messages which are specific to the state of the overall model.
MVC 3 Dependency Injection Enhancements
MVC 3 includes better support for applying Dependency Injection (DI) and also integrating with Dependency Injection/IOC containers.
Currently MVC 3 Preview 1 has support for DI in the below places:
- Controllers (registering & injecting controller factories and injecting controllers)
- Views (registering & injecting view engines, also for injecting dependencies into view pages)
- Action Filters (locating and injecting filters)
url: '/theStore/UpdateProduct',
type: "POST";
data: JSON.stringify(widget),
datatype: "json",
contentType: "application/json; charset=utf-8",
success: function () {
$('#message').html('Saved').fadeIn(),
},
error: function () {
$('#message').html('Error').fadeIn(),
}
});
return false;
});
MVC will allow you to implement the /theStore/UpdateProduct URL on the server by using an action method as below. The UpdateProduct() action method will accept a strongly-typed Product object for a parameter. MVC 3 can now automatically bind an incoming JSON post value to the .NET Product type on the server without having to write any custom binding.
[HttpPost]
public ActionResult UpdateProduct(Product product) {
// save logic here
return null
}
MVC 3 Model Validation Enhancements
MVC 3 builds on the MVC 2 model validation improvements by adding support for several of the new validation features within the System.ComponentModel.DataAnnotations namespace in .NET 4.0:
- Support for the new DataAnnotations metadata attributes like DisplayAttribute.
- Support for the improvements made to the ValidationAttribute class which now supports a new IsValid overload that provides more info on the current validation context, like what object is being validated.
- Support for the new IValidatableObject interface which enables you to perform model-level validation and also provide validation error messages which are specific to the state of the overall model.
MVC 3 Dependency Injection Enhancements
MVC 3 includes better support for applying Dependency Injection (DI) and also integrating with Dependency Injection/IOC containers.
Currently MVC 3 Preview 1 has support for DI in the below places:
- Controllers (registering & injecting controller factories and injecting controllers)
- Views (registering & injecting view engines, also for injecting dependencies into view pages)
- Action Filters (locating and injecting filters)
And this is another important blog about Microsoft .NET and technology:
- Windows 2008 Blog
- SharePoint 2010 Blog
- .NET 4 Blog
And you can visit here if you're looking for ASP.NET MVC 3 hosting
© Geeks with Blogs or respective owner