---
title: "Data Binding in View using MVC"  
description: "In this article I am going to explain how to dynamically bind View data in Model and retrieve data from Model in View through Controller.  Before buil"  
author: "Chris Anderson"  
published: 2011-09-30  
updated: 2020-03-04  
canonical: https://www.mindstick.com/articles/755/data-binding-in-view-using-mvc  
category: "asp.net mvc"  
tags: ["asp.net mvc"]  
reading_time: 2 minutes  

---

# Data Binding in View using MVC

In this article I am going to explain how to dynamically bind [View data](https://www.mindstick.com/forum/159852/view-data-from-database-using-mvc-entity-framework) in Model and [retrieve data](https://www.mindstick.com/forum/159649/how-to-retrieve-data-from-object-tables-on-oracle) from Model in View through [Controller](https://www.mindstick.com/blog/273/passing-values-from-controller-to-view-in-asp-dot-net-mvc).\

##### Before building an application first we have to add the following resource in our MVC application:

1) Controller - HomeController.cs\
2) Model - ModelClass.cs\
3) View - Index.aspx, UserPage.aspx

![Data Binding in View using MVC](https://www.mindstick.com/mindstickarticle/547b9de8-c5c5-41aa-87e9-487e28bc3d4b/images/5afe164e-9802-415a-a7b4-05f76bb53985.png)

##### HomeController.cs

```
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Mvc;using FisrtMVCApp.Models;  namespace FisrtMVCApp.Controllers{     public class HomeController :  Controller    {         //         // GET: /Home/           public ActionResult Index()         {            return View();  //return Index View         }           [HttpPost]         public ActionResult UserPage(ModelClass model)         {            return View(model); //here we are passing the view along with view data         }    }}  
```

ModelClass.cs

```
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.ComponentModel;  namespace FisrtMVCApp.Models{     public class ModelClass    {         [DisplayName("Enter First Name:")]         public string FirstName         {            get;            set;         }           [DisplayName("Enter Last Name:")]         public string LastName         {            get;            set;         }    }}
```

##### Index.aspx

```
 <%@PageLanguage="C#" Inherits="System.Web.Mvc.ViewPage<FisrtMVCApp.Models.ModelClass>" %><!DOCTYPE html>  <html><head runat="server">     <title>Index</title></head><body>    <% using (Html.BeginForm("UserPage","Home",FormMethod.Post)) %><%{ %>     <div>         <center>                <h2>Enter Details:</h2>                <table style="font-family:Calibri" cellpadding="10">                    <tr>                        <td>  <%: Html.LabelFor(m => m.FirstName) %> </td>                        <td>  <%: Html.TextBoxFor(m => m.FirstName) %> </td>                    </tr>                    <tr>                        <td> <%: Html.LabelFor(m => m.LastName) %> </td>                        <td> <%: Html.TextBoxFor(m => m.LastName) %> </td>                    </tr>                    <tr>                        <td colspan="2" align="center">                            <input type="submit" value="Submit"/>                        </td>                    </tr>                       <% } %>                </table>         </center>     </div></body></html>
```

##### UserPage.aspx

```
 <%@PageLanguage="C#" Inherits="System.Web.Mvc.ViewPage<FisrtMVCApp.Models.ModelClass>" %>  <!DOCTYPE html>  <html><head runat="server">     <title>UserPage</title></head><body>     <div>         <h2>Welcome! <%: Html.Label(ViewData.Model.FirstName) %> //here we retreive the                                               data from view, that we pass through controller                                         data from view, that we pass through controller              <%: Html.Label(ViewData.Model.LastName) %></h2>     </div></body></html>
```

Press F5 in order to run [your application](https://answers.mindstick.com/qa/95487/how-do-you-troubleshoot-when-your-application-link-is-not-responding). Enter your First and Last name in [textboxes](https://www.mindstick.com/forum/34206/how-to-add-5-dynamic-textboxes-in-wpf-and-how-to-write-binding-in-c-sharp) respectively and click on [submit button](https://www.mindstick.com/forum/130/its-possible-without-submit-button).

![Data Binding in View using MVC](https://www.mindstick.com/mindstickarticle/547b9de8-c5c5-41aa-87e9-487e28bc3d4b/images/11fd436d-da2e-4a53-9c5b-c8d7698596e7.png)

It will display your name with Welcome message.

![Data Binding in View using MVC](https://www.mindstick.com/mindstickarticle/547b9de8-c5c5-41aa-87e9-487e28bc3d4b/images/e626ce40-66b6-4f56-96a3-a5bf8b794b26.png)

\

---

Original Source: https://www.mindstick.com/articles/755/data-binding-in-view-using-mvc

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
