Creating Asynchronous Actions in ASP.NET MVC
Asynchronous actions allow you to handle more concurrent requests and can be implemented using async / await keywords. Asynchronous actions are useful in situations where you are performing some network operation such as calling a remote service. This article discusses asynchronous actions and also shows how to create them in an ASP.NET MVC.
Posted On : 05 Apr 2014
Problem setting the default value for ASP.NET MVC DropDownList
Recently one of the readers reported a problem that the DropDownList helper is not working as expected. The problem was resolved by slightly tweaking the code but since it sounded like a tricky thing that many beginners would stumble upon I am writing this post. Let's see what the problem is, its cause and finally the little tweak that I mentioned earlier.
Posted On : 03 Apr 2014
Using Attribute Routing in ASP.NET MVC
ASP.NET MVC maps a URL to an action method through what is known as Routing. By default an ASP.NET MVC URL includes a controller and an action name where the request finally lands. However, you can customize many aspects of a route such as root prefix and route parameters. ASP.NET MVC 5 allows you to define routes through certain attributes. This attribute routing is simpler and more intuitive than the older technique of defining routes because a route definition is closer to the controller and its action method. This article discusses how attribute routing can be used with examples.
Posted On : 27 Mar 2014
Handling Errors in ASP.NET MVC Applications
No matter how proficiently you developed your application there are chances that your code may not work as expected and will generate an error at runtime. Users may enter some invalid data, mathematical calculations can go wrong, some network level fault may cause errors and more. That is why it is always a good idea to implement a robust error handling mechanism in your web application. To that end ASP.NET MVC offers several techniques that help you build such an error handling mechanism. This article discusses them with examples.
Posted On : 13 Mar 2014
Implementing Ajax Login in ASP.NET MVC
Implementing Ajax based login involves many of the same steps as the normal forms authentication. However, the login page doesn't send user ID and password to the server through a standard form submission. Instead, user credentials are sent to the server via an Ajax request. The credentials are then validated on the server and the result of the verification process is conveyed to the client. If the login attempt was successful, the user is taken to the secured area of the website.
Posted On : 26 Feb 2014
Model Binding to List of Objects in ASP.NET MVC
Showing a single record for editing is quite common and the default model binding of ASP.NET MVC takes care of mapping the form fields to the model properties. However, sometimes you need to edit multiple records. For example, you may want to display an editable grid to the end user filled with existing data. The user can edit the values from multiple rows and hit Save in an attempt to save the data. In this case multiple model objects are being submitted to the action method. The single record editing works on the assumption that form field names from the view match the corresponding model property names. However, when multiple model objects are submitted this assumption is no longer valid. Luckily, by tweaking the form field names you can get this to work as expected.
Posted On : 18 Feb 2014
Posting multiple pieces of data to Web API
Web API allows you to create RESTful services easily. A typical Web API implements GET, POST, PUT and DELETE verbs by writing methods intended to handle each of these HTTP verbs. Although the actual method implementation can be anything as per your application requirement, you need to follow certain method signatures. For example, the Post() method signature accepts the data accompanying the request as a single parameter.
Posted On : 30 Dec 2013
Understanding ViewData, ViewBag and TempData
While working with ASP.NET MVC applications you often need to pass data from controller action methods to the view. And there are various techniques to accomplish that goal - ViewData, ViewBag and TempData. This article explains the these techniques, the difference between them and usage scenarios.
Posted On : 08 Nov 2013
Creating Wizard in ASP.NET MVC (Part 3 - jQuery)
In Part 1 and Part 2 of this article series you developed a wizard in an ASP.NET MVC application using full page postback and Ajax helper respectively. In this final part of this series you will develop a client side wizard using jQuery. The navigation between various wizard steps (Next, Previous) happens without any postback (neither full nor partial). The only step that causes form submission to the server is clicking on the Finish wizard button.
Posted On : 06 Nov 2013
Creating Wizard in ASP.NET MVC (Part 2 - Ajax Helper)
In Part 1 of this article series you developed a wizard in an ASP.NET MVC application. Although the wizard developed in Part 1 works as expected it has one shortcoming. It causes full page postback whenever you click on Previous or Next button. This behavior may not pose much problem if a wizard has only a few steps. However, if a wizard has many steps and each step accepts many entries then full page postback can deteriorate the user experience. To overcome this shortcoming you can add Ajax to the wizard so that only the form is posted to the server. In this part of the series you will convert the application developed in Part 1 to use Ajax.
Posted On : 23 Oct 2013