Tag: ASP.NET

ASP.NET MVC 2 Beta – new features

Posted by – November 18, 2009

.NET LogoYesterday at PDC 09 Bob Muglia announced the release of ASP.NET MVC 2 Beta. This release contains a lot of new, interesting stuff. Below you can find a list of new features taken from official release notes.

New RenderAction method

Html.RenderAction (and its counterpart Html.Action) is an HTML helper method that calls into an action method from within a view and renders the output of the action method in place. Html.RenderAction writes directly to the response, whereas Html.Action returns a string with the output. RenderAction works only with actions that render views.

Strongly typed UI helpers

ASP.NET MVC 2 includes new expression-based versions of existing HTML helper methods. The new helpers include the following:

  • ValidationMessageFor
  • TextAreaFor
  • TextBoxFor
  • HiddenFor
  • DropDownListFor

TempDataDictionary improvements

The behavior of the TempDataDictionary class has been changed slightly to address scenarios where temp data was either removed prematurely or persisted longer than necessary. For example, in cases where temp data was read in the same request in which it was set, the temp data was persisting for the next request even though the intent was to remove it. In other cases, temp data was not persisted across multiple consecutive redirects.

To address these scenarios, the TempDataDictionary class was changed so that all the keys survive indefinitely until the key is read from the TempDataDictionary object. The Keep method was added to TempDataDictionary to let you indicate that the value should not be removed after reading. The RedirectToActionResult is an example where the Keep method is called in order to retain all the keys for the next request.

Client validation library

MicrosoftMvcAjax.js now includes a client-side validation library that is used to provide client validation for models in ASP.NET MVC. To enable client validation, include the following two scripts in your view.

  • MicrosoftAjax.js
  • MicrosoftMvcAjax.js

The following example shows a view with client validation enabled.

<script type="text/javascript" src="MicrosoftAjax.js"></script><script type="text/javascript" src="MicrosoftMvcAjax.js"></script>

  //...

“Add Area” dialog box

ASP.NET MVC 2 Beta includes a new Add Area context menu item when you right-click either the root project node or the Areas folder (if one exists). If a root Areas folder does not already exist, the command creates one, and it then creates the files and folders for the area that you specify.

Calling action methods asynchronously

The AsyncController class is a base class for controllers that enables action methods to be called asynchronously. This lets an action method call external services such as a Web service without blocking the current thread. For more information, see Using an Asynchronous Controller in ASP.NET MVC In the ASP.NET MVC 2 documentation.

Blank project template

In response to customer feedback, an empty ASP.NET MVC project template is now included with ASP.NET MVC 2 Beta. This empty project template contains a minimal set of files used to build a new ASP.NET MVC project.

Multiple model validator providers

ASP.NET MVC 2 Beta lets you register multiple validation providers. The following example shows how to register multiple providers.

protected void Application_Start() {
    ModelValidatorProviders.Providers.Add(new MyXmlModelValidatorProvider());
    ModelValidatorProviders.Providers.Add(new MyDbModelValidatorProvider());
    //...
}

Multiple value provider registration

In ASP.NET MVC 2 Beta, the single value provider that was available in ASP.NET MVC 1.0 has been split into multiple value providers, one for each source of request data. The new value providers include the following:

  • FormValueProvider
  • RouteDataValueProvider
  • QueryStringValueProvider
  • HttpFileCollectionValueProvider

These value providers are registered by default. You can register additional value providers that pull data from other sources. The following example shows how to register additional value providers in the in Global.asax file.

protected void Application_Start() {
    ValueProviders.Providers.Add(new JsonValueProvider());
    //...
}

Download full ASP.NET MVC 2 Beta Release Notes

ASP.NET MVC in a corporation – part #2

Posted by – September 10, 2009

.NET LogoIn my previous post I have mentioned that I am currently evaluating the ASP.NET MVC in context of usage for building internal corporate applications. During the evaluation I have made my small SWOT analysis and I want to share it with you in order to get to know what your opinion on this topic is. Because my all thoughts reside in a mind map I have dumped them to the plain list:

Strengths:

  • It is based on the Convention over Configuration principle, what means less ceremony in code and more time to focus on business rules;
  • It is highly extensible with many points of extension in every part of application lifecycle.
  • It is highly testable no matter if you are using the TDD or BDD style of unit testing;
  • It is provided by Microsoft – big player on the market, what at least in theory guarantee that the solution will be supported for a long time;
  • It contains a lot of elements known from classic ASP.NET like notion of session, modules, handlers, HTTP context, views based on ASPX pages and ASCX controls. This is quite important if employees have to switch to the ASP.NET MVC and previously they have used classic ASP.NET, because the learning curve is smaller;
  • It does not use the ASP.NET postback and view state models what improves testability and separation between user interface and business logic;
  • It has a routing functionality what enables cleaner URLs;
  • It gives the full control over all aspects of developed application. Many elements of the ASP.NET MVC can be easily replaced with its custom implementation (i.e. view engine, controller factory);
  • It gives the full control over HTML and how views are rendered;
  • It has a great AJAX and JSON support so usage of JavaScript frameworks like jQuery is trivial;
  • It can be easily integrated with any of popular Inversion of Control frameworks;
  • It has quite big community, there is a lot of online documentation and books;

Weaknesses:

  • It is based on the Convention over Configuration principle, what means more magic working in a background (probably harder debugging in some cases);
  • It is not event driven, so can be difficult for people who know only ASP.NET Web Forms to wrap their minds around it;
  • Third party libraries support is not that strong. Not to many companies write extensions for this framework what means more work for internal team;
  • Current version (1.0) requires some additional effort to reduce usage of magic strings to the minimum;

Opportunities:

  • Allows for Test Driven Development – it is build with TDD in mind, so it is much easier to write unit tests, mock objects and to intercept the program flow;

Threats:

  • Bigger ramp-up and training time is required for developers with no or little experience in web application development;

For the time being this is all what came up to my mind. If you have some other thought I will be grateful if you will share them with me.

ASP.NET MVC in a corporation – part #1

Posted by – August 25, 2009

.NET LogoEach big organization like this in which I work is mostly based on processes. Everything from purchase orders to computer hardware is described by them. To be honest I am not a big fan of this way of work. My mind is closer to Agile way of thinking rather than stiff procedures for solving problems but from a bigger perspective this approach seems to work because my current employer has over 100 years and is in very good health.

One thing which is quite funny with processes is that someone has to figure out how each of them should work. In case of my department, which is very young and in its nature very different than rest of the organization, there is no process for many things and we have to develop them for our own. One of our processes is “software development process”. Because the department consists of about 300 developers, administrators and IT specialists and we are using wide range of tools and technologies, the process I mentioned above is very general and describes things in a high level. In order to be able to use it and be safe in case of internal or external audit we need many supporting documents which customize it to a needs of particular team. This detailed documents describe how we should do development in a particular technology (for example .NET Framework), what tools, libraries, methodologies can we use etc. Of course we do not choose tools with which we will work only basing on our subjective opinions and feelings. During choosing process each technology or tool is evaluated by a group of specialist (developers, administrators) and compared to its competitors/equivalents which are available on the market.

Currently I have a pleasure to initialize a process of ASP.NET MVC evaluation. Its purpose is to check if this framework can be used as the replacement for ASP.NET Web Forms and Model-View-Presenter pattern which we are using now. Because the evaluation process does not touch only ASP.NET MVC but also other presentation framework for web .NET application me and my teammates had to prepare a list of things to check and evaluate:

  • Data binding
  • Validation
  • Navigation
  • State saving
  • Embedded controls support
  • Testability
  • Security
  • Collaboration between developers and UI designers
  • Adoption to existing projects
  • Extensibility
  • Community support
  • Documentation availability
  • Development tools support

Order in which topics on the list appear is accidental and all items are in my meaning equal in theirs importance.

Because I am currently at the beginning of the ASP.NET MVC evaluation I do not have to much more I could share with you. Only thing I have prepared is a mind map with detailed topics I will have to take a look at. I will provide more information about pros and cons of the framework for a big companies in a next posts. If you would like to hear about something regarding this topic please leave your comment below.