ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Assign checked (selected) CheckBox value to TextBox using AngularJS in ASP.Net MVC<p>Hi <a class="username" rel="mahesh213"> mahesh213</a>,</p> <p>Check the below code.</p> <p><strong><span style="text-decoration: underline;">Controller</span></strong></p> <pre class="brush: csharp">public class HomeController : Controller { // GET: /Home/ public ActionResult Index() { return View(); } public JsonResult GetAll() { List&lt;Employee&gt; emps = EmployeesList(); return Json(emps, JsonRequestBehavior.AllowGet); } public JsonResult taxes() { List&lt;Tax&gt; taxs = TaxList(); return Json(taxs, JsonRequestBehavior.AllowGet); } [HttpPost] public JsonResult Edit(int? eId) { List&lt;Employee&gt; employee = new List&lt;Employee&gt;(); foreach (var emp in EmployeesList().Where(x =&gt; x.EId == eId)) { employee.Add(new Employee { EId = emp.EId, CId = emp.CId }); } slabs details = new slabs(); details.SlabDetails = employee; return Json(details, JsonRequestBehavior.AllowGet); } private List&lt;Employee&gt; EmployeesList() { List&lt;Employee&gt; emps = new List&lt;Employee&gt;(); emps.Add(new Employee { EId = 1, CId = &#34;1,2&#34;, Name = &#34;aaaa&#34; }); emps.Add(new Employee { EId = 2, CId = &#34;2,3&#34;, Name = &#34;bbbb&#34; }); return emps; } private List&lt;Tax&gt; TaxList() { List&lt;Tax&gt; taxs = new List&lt;Tax&gt;(); taxs.Add(new Tax { Id = 1, Name = &#34;CGST&#34;, Selected = false }); taxs.Add(new Tax { Id = 2, Name = &#34;SGST&#34;, Selected = false }); taxs.Add(new Tax { Id = 3, Name = &#34;IGST&#34;, Selected = true }); return taxs; } public class slabs { public List&lt;Employee&gt; SlabDetails { get; set; } } public class Employee { public int EId { get; set; } public string CId { get; set; } public string Name { get; set; } } public class Tax { public int Id { get; set; } public string Name { get; set; } public bool Selected { get; set; } } }</pre> <p><strong><span style="text-decoration: underline;">View</span></strong></p> <pre class="brush: html">&lt;html xmlns=&#34;http://www.w3.org/1999/xhtml&#34;&gt; &lt;head&gt; &lt;title&gt;Index&lt;/title&gt; &lt;link rel=&#34;stylesheet&#34; href=&#34;https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css&#34; /&gt; &lt;script type=&#34;text/javascript&#34; src=&#34;https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js&#34;&gt;&lt;/script&gt; &lt;script type=&#34;text/javascript&#34; src=&#34;https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js&#34;&gt;&lt;/script&gt; &lt;script type=&#34;text/javascript&#34; src=&#34;https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.5/angular.js&#34;&gt;&lt;/script&gt; &lt;script type=&#34;text/javascript&#34;&gt; var app = angular.module(&#39;MyApp&#39;, []) app.controller(&#39;MyController&#39;, function ($scope, $http, $window, $filter) { GetTaxes(); GetEmployees(); $scope.employee = {}; function GetTaxes() { $scope.taxes = []; $http({ method: &#39;Get&#39;, url: &#39;/Home/taxes&#39; }).success(function (data, status, headers, config) { $scope.taxes = data; }).error(function (data, status, headers, config) { $scope.message = &#39;Unexpected Error&#39;; }); } function GetEmployees() { $scope.employees = []; $http({ method: &#39;Get&#39;, url: &#39;/Home/GetAll&#39; }).success(function (data, status, headers, config) { $scope.employees = data; }).error(function (data, status, headers, config) { $scope.message = &#39;Unexpected Error&#39;; }); } //Edit code for Slab Details $scope.Edit = function (id) { $scope.employee = $filter(&#39;filter&#39;)($scope.employees, { EId: id })[0]; $.post(&#34;/Home/Edit/&#34;, { eId: id }, function (r) { $scope.Customers = []; for (var i = 0; i &lt; r.SlabDetails.length; i++) { var slab = {}; slab.EId = r.SlabDetails[i].EId; slab.CId = r.SlabDetails[i].CId; $scope.Customers.push(slab); } $scope.$apply(); }); } $scope.SetChecked = function (cid) { for (var i = 0; i &lt; $scope.taxes.length; i++) { $scope.taxes[i].Selected = false; for (var j = 0; j &lt; cid.split(&#39;,&#39;).length; j++) { if (cid.split(&#39;,&#39;)[j] == $scope.taxes[i].Id) { $scope.taxes[i].Selected = true; } } } } $scope.GetChecked = function () { $scope.UpdatedCheckBox = &#34;&#34;; for (var i = 0; i &lt; $scope.taxes.length; i++) { if ($scope.taxes[i].Selected) { $scope.UpdatedCheckBox += $scope.taxes[i].Id + &#34;,&#34;; } } $scope.Customers[0].CId = $scope.UpdatedCheckBox.slice(0, -1); } }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div ng-app=&#34;MyApp&#34; ng-controller=&#34;MyController&#34;&gt; &lt;table class=&#34;table table-bordered table-hover table-striped&#34; ng-show=&#34;Customers&#34;&gt; &lt;tr&gt; &lt;th&gt;CId&lt;/th&gt; &lt;th&gt;Orders&lt;/th&gt; &lt;/tr&gt; &lt;tbody ng-repeat=&#34;m in Customers&#34;&gt; &lt;tr&gt; &lt;td&gt;&lt;input type=&#34;text&#34; ng-model=&#34;m.CId&#34; /&gt;&lt;/td&gt; &lt;td&gt; &lt;button type=&#34;button&#34; ng-init=&#34;clicked=false&#34; ng-click=&#34;clicked=!clicked;SetChecked(m.CId)&#34;&gt;View&lt;/button&gt; &lt;div class=&#34;modal fade in&#34; aria-hidden=&#34;false&#34; style=&#34;display: block;&#34; ng-show=&#34;clicked&#34;&gt; &lt;div class=&#34;modal-dialog&#34;&gt; &lt;div class=&#34;modal-content&#34;&gt; &lt;div class=&#34;modal-header&#34;&gt; &lt;button type=&#34;button&#34; class=&#34;close&#34; ng-click=&#34;clicked=false&#34;&gt;&times;&lt;/button&gt; &lt;h4 style=&#34;margin-left: 15px; text-align: center;&#34;&gt;Tax Details&lt;/h4&gt; &lt;/div&gt; &lt;div class=&#34;modal-body&#34;&gt; &lt;fieldset&gt; &lt;!-- Form Name --&gt; &lt;label style=&#34;margin-left: 25px;&#34; ng-repeat=&#34;o in taxes&#34; class=&#34;checkbox&#34;&gt; &lt;input type=&#34;hidden&#34; ng-model=&#34;o.Id&#34; /&gt; &lt;input type=&#34;checkbox&#34; name=&#34;subject&#34; ng-model=&#34;o.Selected&#34; ng-change=&#34;GetChecked()&#34; /&gt;{{o.Name}} &lt;/label&gt; &lt;/fieldset&gt; &lt;/div&gt; &lt;div class=&#34;modal-footer&#34;&gt; &lt;button type=&#34;button&#34; class=&#34;btn btn-primary&#34; ng-click=&#34;clicked=false;&#34;&gt;Ok&lt;/button&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;div&gt; &lt;table class=&#34;table table-bordered table-hover table-striped&#34;&gt; &lt;tr&gt; &lt;th&gt;CId&lt;/th&gt; &lt;th&gt;EId&lt;/th&gt; &lt;th&gt;&amp;nbsp;&lt;/th&gt; &lt;/tr&gt; &lt;tbody ng-repeat=&#34;e in employees&#34;&gt; &lt;tr&gt; &lt;td&gt;{{e.EId}}&lt;/td&gt; &lt;td&gt;{{e.CId}}&lt;/td&gt; &lt;td&gt;&lt;a ng-click=&#34;Edit(e.EId)&#34; href=&#34;&#34;&gt;Edit&lt;/a&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt;</pre> <p><strong><span style="text-decoration: underline;">Screenshot</span></strong></p> <p><img src="https://i.imgur.com/7mzHM52.gif" alt="" width="472" height="174" /></p>https://www.aspforums.net:443/Threads/188166/Assign-checked-selected-CheckBox-value-to-TextBox-using-AngularJS-in-ASPNet-MVC/https://www.aspforums.net:443/Threads/188166/Assign-checked-selected-CheckBox-value-to-TextBox-using-AngularJS-in-ASPNet-MVC/Wed, 07 Aug 2019 06:27:53 GMT