{"id":4882,"date":"2024-02-06T07:18:47","date_gmt":"2024-02-06T07:18:47","guid":{"rendered":"https:\/\/isophal.com\/?p=4882"},"modified":"2024-02-06T07:18:48","modified_gmt":"2024-02-06T07:18:48","slug":"introduction-to-model-binding-in-asp-net-mvc-part-1","status":"publish","type":"post","link":"https:\/\/isophal.com\/news\/2024\/02\/06\/4882.html\/","title":{"rendered":"Introduction To Model Binding in ASP.Net MVC: Part 1"},"content":{"rendered":"\n<p><strong>Introduction<\/strong><\/p>\n\n\n\n<p>Today we&#8217;ll learn about Model Binding in MVC applications. Model Binding allows you to map and bind the HTTP request data with a model. If you want to work with the form data, Model Binding makes it easier because the requested data is submitted automatically into a data model that we specify. The Default Binder is used to do this, if we go deep intp this.<\/p>\n\n\n\n<p>In that context, you&#8217;ll learn here the model biding working with the various types of models such as:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>No Binding<\/li>\n\n\n\n<li>Binding with Simple Types<\/li>\n\n\n\n<li>Binding with Class Types<\/li>\n\n\n\n<li>Binding with Class Properties<\/li>\n<\/ul>\n\n\n\n<p><strong>Before Getting Started<\/strong><\/p>\n\n\n\n<p>You must be familiar with the knowledge of MVC or you can refer to&nbsp;<a href=\"https:\/\/www.c-sharpcorner.com\/UploadFile\/4b0136\/getting-started-with-view-in-mvc-5\/\">Getting Started with MVC<\/a>. Here, I am developing an application on Visual Studio 2013 using MVC 5 Project Template. So, start with the following points:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Open Visual Studio 2013 and click on &#8220;New Project&#8221;<\/li>\n\n\n\n<li>Select the ASP.NET Web Application and enter the name to it<\/li>\n\n\n\n<li>Select the MVC project template to develop the application<\/li>\n<\/ul>\n\n\n\n<p><strong>No Binding<\/strong><\/p>\n\n\n\n<p>In this section we&#8217;ll see how form data is to be used without no Model Binding. So, follow the procedure below.<\/p>\n\n\n\n<p><strong>Step 1:<\/strong>&nbsp;Scaffold a new MVC empty controller named&nbsp;<em>&#8220;ModelBinding<\/em>&#8220;.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.c-sharpcorner.com\/UploadFile\/4b0136\/introduction-to-model-binding-in-Asp-Net-mvc\/Images\/Scaffolding%20MVC%20Empty%20Controller.jpg\" alt=\"Scaffolding MVC Empty Controller\"\/><\/figure>\n\n\n\n<p><strong>Step 2:<\/strong>&nbsp;Modify the Index() method with the following code:<\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"1\">\n<li><strong>public<\/strong>&nbsp;ActionResult&nbsp;Index()&nbsp;&nbsp;<\/li>\n\n\n\n<li>{&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<strong>if<\/strong>&nbsp;(Request.Form.Count&nbsp;&gt;&nbsp;0)&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>string<\/strong>&nbsp;ID=&nbsp;Request.Form[&#8220;StudentID&#8221;];&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>string<\/strong>&nbsp;FirstName&nbsp;=&nbsp;Request.Form[&#8220;StudentFirstName&#8221;];&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ViewBag.Message&nbsp;=&nbsp;&#8220;Your&nbsp;Student&nbsp;retrieved&nbsp;successfully&nbsp;with&nbsp;an&nbsp;ID&#8221;&nbsp;+&nbsp;&#8221;&nbsp;&#8221;&nbsp;+ID+&nbsp;&#8220;!!&#8221;;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<strong>return<\/strong>&nbsp;View();&nbsp;&nbsp;<\/li>\n\n\n\n<li>}&nbsp;<\/li>\n<\/ol>\n\n\n\n<p><strong>Step 3:<\/strong>&nbsp;Generate the view named Index and replace the code with the following code:<\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"1\">\n<li>@{&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;ViewBag.Title&nbsp;=&nbsp;&#8220;Index&#8221;;&nbsp;&nbsp;<\/li>\n\n\n\n<li>}&nbsp;&nbsp;<\/li>\n\n\n\n<li>&lt;h2&gt;Index&lt;\/h2&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>@using&nbsp;(Html.BeginForm())&nbsp;&nbsp;<\/li>\n\n\n\n<li>{&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&lt;div&nbsp;<strong>class<\/strong>=&#8221;form-horizontal&#8221;&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h4&gt;Enter&nbsp;Details&lt;\/h4&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;hr&nbsp;\/&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div&nbsp;<strong>class<\/strong>=&#8221;form-group&#8221;&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@Html.Label(&#8220;ID:&#8221;,&nbsp;<strong>new<\/strong>&nbsp;{&nbsp;@<strong>class<\/strong>&nbsp;=&nbsp;&#8220;col-md-2&nbsp;control-label&#8221;&nbsp;})&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div&nbsp;<strong>class<\/strong>=&#8221;col-md-10&#8243;&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@Html.TextBox(&#8220;StudentID&#8221;)&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/div&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/div&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div&nbsp;<strong>class<\/strong>=&#8221;form-group&#8221;&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@Html.Label(&#8220;Name:&#8221;,&nbsp;<strong>new<\/strong>&nbsp;{&nbsp;@<strong>class<\/strong>&nbsp;=&nbsp;&#8220;col-md-2&nbsp;control-label&#8221;&nbsp;})&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div&nbsp;<strong>class<\/strong>=&#8221;col-md-10&#8243;&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@Html.TextBox(&#8220;StudentFirstName&#8221;)&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/div&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/div&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div&nbsp;<strong>class<\/strong>=&#8221;form-group&#8221;&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div&nbsp;<strong>class<\/strong>=&#8221;col-md-offset-2&nbsp;col-md-10&#8243;&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;input&nbsp;type=&#8221;submit&#8221;&nbsp;value=&#8221;Submit&#8221;&nbsp;<strong>class<\/strong>=&#8221;btn&nbsp;btn-default&#8221;&nbsp;\/&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@ViewBag.Message&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/div&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/div&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/div&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>}&nbsp;<\/li>\n<\/ol>\n\n\n\n<p><strong>Step 4:<\/strong>&nbsp;Run the application and open the Index view of your controller. Enter some data and you can see the following screenshot while clicking on &#8220;Submit&#8221;.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.c-sharpcorner.com\/UploadFile\/4b0136\/introduction-to-model-binding-in-Asp-Net-mvc\/Images\/Model%20with%20No%20Binding.jpg\" alt=\"Model with No Binding\"\/><\/figure>\n\n\n\n<p><strong>Binding with Simple Types<\/strong><\/p>\n\n\n\n<p>As you know the&nbsp;<em>DefaultBinder<\/em>&nbsp;object handles the default Model Binding. The MVC provides the&nbsp;<em>System.Web.Mvc.DefaultModelBinder<\/em>&nbsp;that is used to work with the simple types or classes and collections. Let&#8217;s see how it works.<\/p>\n\n\n\n<p><strong>Step 1:<\/strong>&nbsp;Modify the&nbsp;<em>Index()<\/em>&nbsp;in your controller with the following code:<\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"1\">\n<li><strong>public<\/strong>&nbsp;ActionResult&nbsp;Index()&nbsp;&nbsp;<\/li>\n\n\n\n<li>{&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<strong>return<\/strong>&nbsp;View();&nbsp;&nbsp;<\/li>\n\n\n\n<li>}&nbsp;&nbsp;<\/li>\n\n\n\n<li>[HttpPost]&nbsp;&nbsp;<\/li>\n\n\n\n<li><strong>public<\/strong>&nbsp;ActionResult&nbsp;Index(<strong>string<\/strong>&nbsp;studentid,&nbsp;<strong>string<\/strong>&nbsp;studentfirstname)&nbsp;&nbsp;<\/li>\n\n\n\n<li>{&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;ViewBag.Message&nbsp;=&nbsp;&#8220;Your&nbsp;Student&nbsp;retrieved&nbsp;successfully&nbsp;with&nbsp;an&nbsp;ID&#8221;&nbsp;+&nbsp;&#8221;&nbsp;&#8221;&nbsp;+&nbsp;studentid&nbsp;+&nbsp;&#8220;!!&#8221;;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<strong>return<\/strong>&nbsp;View();&nbsp;&nbsp;<\/li>\n\n\n\n<li>}&nbsp;<\/li>\n<\/ol>\n\n\n\n<p><strong>Step 2:<\/strong>&nbsp;Now run the controller and enter the id.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.c-sharpcorner.com\/UploadFile\/4b0136\/introduction-to-model-binding-in-Asp-Net-mvc\/Images\/Model%20Binding%20with%20Simple%20Types.jpg\" alt=\"Model Binding with Simple Types\"\/><\/figure>\n\n\n\n<p><strong>Note:<\/strong>&nbsp;Please ensure that the variables you define in the&nbsp;<em>Index()<\/em>&nbsp;is the same name as you defined in the view. Just view at the following screenshot if we define the following variables:<\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"1\">\n<li><strong>public<\/strong>&nbsp;ActionResult&nbsp;Index(<strong>string<\/strong>&nbsp;studentid,&nbsp;<strong>string<\/strong>&nbsp;tudentfirstname)&nbsp;<\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.c-sharpcorner.com\/UploadFile\/4b0136\/introduction-to-model-binding-in-Asp-Net-mvc\/Images\/Variables%20in%20Local.jpg\" alt=\"Variables in Local\"\/><\/figure>\n\n\n\n<p>You can see that the&nbsp;<em>null<\/em>&nbsp;value is assigned in the&nbsp;<em>tudentfirstname<\/em>&nbsp;variable.<\/p>\n\n\n\n<p><strong>Binding with Class Types<\/strong><\/p>\n\n\n\n<p><strong>Step 1:<\/strong>&nbsp;Add a class named&nbsp;<em>&#8220;Student&#8221;<\/em>&nbsp;in the Models folder and replace the code with the following code:<\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"1\">\n<li><strong>public<\/strong>&nbsp;<strong>class<\/strong>&nbsp;Student&nbsp;&nbsp;<\/li>\n\n\n\n<li>{&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<strong>public<\/strong>&nbsp;<strong>string<\/strong>&nbsp;StudentID&nbsp;{&nbsp;<strong>get<\/strong>;&nbsp;<strong>set<\/strong>;&nbsp;}&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<strong>public<\/strong>&nbsp;<strong>string<\/strong>&nbsp;StudentFirstName&nbsp;{&nbsp;<strong>get<\/strong>;&nbsp;<strong>set<\/strong>;&nbsp;}&nbsp;&nbsp;<\/li>\n\n\n\n<li>}&nbsp;<\/li>\n<\/ol>\n\n\n\n<p><strong>Step 2:&nbsp;<\/strong>Now modify the<em>&nbsp;HttpPost Index()<\/em>&nbsp;method with the following code:<\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"1\">\n<li>[HttpPost]&nbsp;&nbsp;<\/li>\n\n\n\n<li><strong>public<\/strong>&nbsp;ActionResult&nbsp;Index(Student&nbsp;s)&nbsp;&nbsp;<\/li>\n\n\n\n<li>{&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;ViewBag.Message&nbsp;=&nbsp;&#8220;Your&nbsp;Student&nbsp;retrieved&nbsp;successfully&nbsp;with&nbsp;an&nbsp;ID&#8221;&nbsp;+&nbsp;&#8221;&nbsp;&#8221;&nbsp;+&nbsp;s.StudentID&nbsp;+&nbsp;&#8220;!!&#8221;;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<strong>return<\/strong>&nbsp;View();&nbsp;&nbsp;<\/li>\n\n\n\n<li>}&nbsp;<\/li>\n<\/ol>\n\n\n\n<p><strong>Step 3:<\/strong>&nbsp;Now run the application and open the controller.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.c-sharpcorner.com\/UploadFile\/4b0136\/introduction-to-model-binding-in-Asp-Net-mvc\/Images\/Model%20Binding%20with%20Class%20Types.jpg\" alt=\"Model Binding with Class Types\"\/><\/figure>\n\n\n\n<p><strong>Binding with Class Properties<\/strong><\/p>\n\n\n\n<p><strong>Step 1:<\/strong>&nbsp;Add a class named&nbsp;<em>&#8220;Contact&#8221;<\/em>&nbsp;in the Models folder and replace the code with the following code:<\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"1\">\n<li><strong>public<\/strong>&nbsp;<strong>class<\/strong>&nbsp;Contact&nbsp;&nbsp;<\/li>\n\n\n\n<li>{&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<strong>public<\/strong>&nbsp;Int64&nbsp;Mobile&nbsp;{&nbsp;<strong>get<\/strong>;&nbsp;<strong>set<\/strong>;&nbsp;}&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<strong>public<\/strong>&nbsp;<strong>string<\/strong>&nbsp;Email&nbsp;{&nbsp;<strong>get<\/strong>;&nbsp;<strong>set<\/strong>;&nbsp;}&nbsp;&nbsp;<\/li>\n\n\n\n<li>}&nbsp;<\/li>\n<\/ol>\n\n\n\n<p><strong>Step 2:<\/strong>&nbsp;Modify the&nbsp;<em>Student<\/em>&nbsp;class with the following highlighted code:<\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"1\">\n<li><strong>public<\/strong>&nbsp;<strong>class<\/strong>&nbsp;Student&nbsp;&nbsp;<\/li>\n\n\n\n<li>{&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<strong>public<\/strong>&nbsp;<strong>string<\/strong>&nbsp;StudentID&nbsp;{&nbsp;<strong>get<\/strong>;&nbsp;<strong>set<\/strong>;&nbsp;}&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<strong>public<\/strong>&nbsp;<strong>string<\/strong>&nbsp;StudentFirstName&nbsp;{&nbsp;<strong>get<\/strong>;&nbsp;<strong>set<\/strong>;&nbsp;}&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<strong>public<\/strong>&nbsp;Contact&nbsp;StudentContact&nbsp;{&nbsp;<strong>get<\/strong>;&nbsp;<strong>set<\/strong>;&nbsp;}&nbsp;&nbsp;<\/li>\n\n\n\n<li>}&nbsp;<\/li>\n<\/ol>\n\n\n\n<p><strong>Step 3:<\/strong>&nbsp;Add the following markup in the&nbsp;<em>Index.cshtml<\/em>&nbsp;file:<\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"1\">\n<li>&lt;div&nbsp;<strong>class<\/strong>=&#8221;form-group&#8221;&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;@Html.Label(&#8220;Mobile:&#8221;,&nbsp;<strong>new<\/strong>&nbsp;{&nbsp;@<strong>class<\/strong>&nbsp;=&nbsp;&#8220;col-md-2&nbsp;control-label&#8221;&nbsp;})&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&lt;div&nbsp;<strong>class<\/strong>=&#8221;col-md-10&#8243;&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@Html.TextBox(&#8220;StudentContact.Mobile&#8221;)&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/div&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&lt;\/div&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&lt;div&nbsp;<strong>class<\/strong>=&#8221;form-group&#8221;&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;@Html.Label(&#8220;Email:&#8221;,&nbsp;<strong>new<\/strong>&nbsp;{&nbsp;@<strong>class<\/strong>&nbsp;=&nbsp;&#8220;col-md-2&nbsp;control-label&#8221;&nbsp;})&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&lt;div&nbsp;<strong>class<\/strong>=&#8221;col-md-10&#8243;&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@Html.TextBox(&#8220;StudentContact.Email&#8221;)&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/div&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&lt;\/div&gt;&nbsp;<\/li>\n<\/ol>\n\n\n\n<p><strong>Step 4:<\/strong>&nbsp;When you call the&nbsp;<em>StudentContact<\/em>&nbsp;in the controller and after running the application and providing the information, the defaultbinder maps the property automatically, see in the locals screenshot below:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.c-sharpcorner.com\/UploadFile\/4b0136\/introduction-to-model-binding-in-Asp-Net-mvc\/Images\/Local%20with%20Class%20Properties.jpg\" alt=\"Local with Class Properties\"\/><\/figure>\n\n\n\n<p><strong>Summary<\/strong><\/p>\n\n\n\n<p>This article described the Model Binding with various types like no binding, simple type, class types. In the next part we&#8217;ll learn more types binding. Thanks for reading.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Today we&#8217;ll learn about Model Binding&hellip;<\/p>\n","protected":false},"author":1,"featured_media":4885,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[189,188,140],"tags":[191],"class_list":["post-4882","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-asp-net","category-c-sharp","category-programming","tag-asp-net"],"_links":{"self":[{"href":"https:\/\/isophal.com\/news\/wp-json\/wp\/v2\/posts\/4882","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/isophal.com\/news\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/isophal.com\/news\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/isophal.com\/news\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/isophal.com\/news\/wp-json\/wp\/v2\/comments?post=4882"}],"version-history":[{"count":1,"href":"https:\/\/isophal.com\/news\/wp-json\/wp\/v2\/posts\/4882\/revisions"}],"predecessor-version":[{"id":4886,"href":"https:\/\/isophal.com\/news\/wp-json\/wp\/v2\/posts\/4882\/revisions\/4886"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/isophal.com\/news\/wp-json\/wp\/v2\/media\/4885"}],"wp:attachment":[{"href":"https:\/\/isophal.com\/news\/wp-json\/wp\/v2\/media?parent=4882"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/isophal.com\/news\/wp-json\/wp\/v2\/categories?post=4882"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/isophal.com\/news\/wp-json\/wp\/v2\/tags?post=4882"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}