Introduction
This article explains how to create a User Control in the Web API. We add a "MVC4 View User Control (ASPX)" in which we create a link that calls the action method from the "Controller".
Procedure for creating the User Control in the Web API.
Step 1
Create an API application as in the following:
- Start Visual Studio 2012.
- From the start window Select "Installed" -> "Visual C#" -> "Web".
- Select "ASP.NET MVC4 Web Application" and click the "OK" button.

- From the "MVC4 Project" window select "Web API".

- Click the "Ok" button.
Step 2
Now we add a User Control named "UserControlAPI.ascx".
- In the "Solution Explorer".
- Right-click on the "Shared folder", select "Add" -> "New Item".
- Select "Installed" -> "Visual C#" -> "Web".
- Select "MVC4 View User Control (ASPX)".

- Click the "Ok" button. It will be shown in the Shared folder.

Add the following lines of code:
- <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
- <%: Html.ActionLink("ClickMe","Display") %>
In this code "ClickMe" is a link and "Display" is an action method. When we click on the link "ClickMe", it calls the action method "Display" from the controller.
Step 3
Now in the "HomeController" we create an action method "Display". This file exists in the:
- In the "Solution Explorer".
- Spread the "Controller" folder.
- Select the "HomeController".

Add the following code:




Join the conversation! Your thoughts help the community grow.