---
title: "User Controls in ASP.NET MVC"  
description: "In this article I will explain how to create and render a User Control in ASP.NET MVC.  Create a User Control:To create a user control you have to a"  
author: "Chris Anderson"  
published: 2011-10-08  
updated: 2020-03-04  
canonical: https://www.mindstick.com/articles/770/user-controls-in-asp-dot-net-mvc  
category: "asp.net mvc"  
tags: ["asp.net mvc"]  
reading_time: 2 minutes  

---

# User Controls in ASP.NET MVC

In this article I will explain how to create and render a User Control in ASP.NET MVC.\

Create a User Control:

To create a user control you have to add a new item (MVC 3 View User Control (ASPX)) from an Add New Item template. You can change the name of user control as you want. Here I change it as UserControl.ascx.

![User Control in ASP.NET MVC](https://www.mindstick.com/mindstickarticle/abd1cc3a-4515-4980-9ada-3d3b23c7a8c8/images/fe0b5786-617b-4ac1-ae7a-bb00fd709fde.png)

After adding the user control check whether your user control exists in Shared folder or not and if it not exists in Shared folder then cut the UserControl.ascx from the other locationand paste it into Shared folder.

![User Control in ASP.NET MVC](https://www.mindstick.com/mindstickarticle/abd1cc3a-4515-4980-9ada-3d3b23c7a8c8/images/238d5190-07e1-48e3-9fec-3fe9314d3d7a.png)

Here in a UserControl file I simply create a link that call a ShowData() action method from the controller.

```
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>

<%: Html.ActionLink("Home","ShowData",) %>
```

Create a ShowData action in a Controller that returns a formatted string.

```
using System.Web.Mvc;

namespace UserControlDemo.Controllers
{
     public class HomeController :  Controller
    {
         public ActionResult Index()
         {
            return View();
         }
         public string ShowData()
        {
            return  "<h3>Page Under Construction</h3>";
        }
    }
}
```

After creating a user control you have to render it in your view. Here in an index view I am rendering a User control:

```
<html>
<head runat="server">
     <title>Index</title>
</head>
<body>
     <div>
         <h3><% Html.RenderPartial("UserControl"); %></h3>
     </div>
</body>
</html>
```

After render a User Control you can see the output as below:

![User Control in ASP.NET MVC](https://www.mindstick.com/mindstickarticle/abd1cc3a-4515-4980-9ada-3d3b23c7a8c8/images/783a28c7-9491-4f37-bf5c-834f651590ef.png)

When you click on Home link it will display a message as below:

![User Control in ASP.NET MVC](https://www.mindstick.com/mindstickarticle/abd1cc3a-4515-4980-9ada-3d3b23c7a8c8/images/f4fd48d9-80d9-4d1c-8747-17243d513d8f.png)

Thank you for reading this article and I think this will help you a lot.

---

Original Source: https://www.mindstick.com/articles/770/user-controls-in-asp-dot-net-mvc

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
