ASP.NET MVC

123456
Self-Hosting an ASP.NET Web API
ASP.NET Web API can be either be hosted in IIS or in a separate host process. The former approach is usually appropriate when the Web API is part of a web application and one or more web applications are going to consume it. The later approach is suitable when you wish to avoid the overhead of hosting the Web API in IIS and want to have something lightweight. Hosting a Web API inside IIS is quite straightforward as the process is identical to hosting a web application. On the other hand, hosting a Web API in it's own process requires the creation of a host application and is referred as self-hosting. This article shows in step-by-step manner how to self-host a Web API and how to consume it using a client application.
Posted On : 22 Jul 2014
Passing data from one controller to another in ASP.NET MVC
At times you need to pass data from an action method belonging to one controller to an action method belonging to another controller. There are three ways to accomplish this task. They are - Pass data as query string, pass data in TempData, and pass data as route parameters. Let's quickly see how each of these three approaches work.
Posted On : 16 Jul 2014
Creating Your Own "TempBag" in ASP.NET MVC
Some time back during one of my training programs I was asked this question by a beginner in ASP.NET MVC - "Can we have TempBag wrapper for TempData just as we have ViewBag for ViewData?" Whether such a wrapper is needed is not is a different question but if you wish you can create one using dynamic objects of C# language. Here I am going to show a quick way to wrap TempData into our own TempBag and then using it in the controller and view.
Posted On : 28 Jun 2014
Video : How to organize your ASP.NET MVC solution in Visual Studio?
A lot of beginners ask this question - How should I organize my MVC projects? There is no fixed answer to this question because a lot of things depend on the size and complexity of the system being developed. However, beginners need a starting point from where they can take it forward. To that end, this video shows one possible organization of various parts of an MVC application. Remember that my aim is to present a simple and structured organization that can easily be extended or modified as per requirement.
Posted On : 18 Jun 2014
Working with Cookies in Web API and HttpClient
ASP.NET applications often use cookies to store user specific pieces of information. Not just web forms and MVC applications, Web API too can use cookies. Sometimes developers device an authentication scheme revolving around cookie as an authentication ticket. Although this article won't show you how to develop such a scheme, it illustrates how cookies can be issued and used in Web API. Specifically you will learn: How to set cookies from a Web API controller and read those cookies in a client application and how to set cookies from a client application (HttpClient) and read those cookies in a Web API controller.
Posted On : 10 Jun 2014
Understanding Dependency Injection
If you ever developed ASP.NET MVC applications you probably have come across this term - Dependency Injection. Dependency Injection is a way to implement the Dependency Inversion Principle. Simply put, Dependency Injection is a design pattern that helps a class separate the logic of creating dependent objects. The result of this separation is a loosely coupled system where there is no rigid dependency between two concrete implementations. This article discusses what Dependency Injection is and illustrates its use in an ASP.NET MVC application.
Posted On : 03 Jun 2014
Dealing with Multiple Instances of Partial Views and Model Binding in ASP.NET MVC
ASP.NET model binding is quite powerful and flexible. It caters to most of the scenarios without much configuration from developers. However, at times you may need to intervene in order to achieve the desired model binding effect. One such situation is when you use multiple instance of a partial page on a view. This article shows one possible approach to deal with such situations.
Posted On : 28 May 2014
Cascading DropDownLists using "Eager Loading" on client side
One of my earlier articles shows how to create cascading DropDownLists by making Ajax calls to the MVC action methods. While that approach is quite common and popular recently a reader asked whether something similar can be done without making any Ajax calls. If you want to implement cascading dropdownlists purely on client side then you will need to "eagerly load" all the data needed by them at the time of loading the page. This data can be stored in a hidden field and used as and when needed. Obviously this technique is not suitable for huge amount of data since everything is loaded at once on the client side. However, if the data is small and you understand the implications of loading it in advance here is how you can accomplish the task.
Posted On : 13 May 2014
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
123456