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.Display File Name on Edit Button Click using AngularJS in ASP.Net MVC<p>Hi <a class="username" rel="mahesh213"> mahesh213</a>,</p> <p>Refe below code.</p> <p><strong><span style="text-decoration: underline;">Controller</span></strong></p> <pre class="brush: csharp">public class HomeController : Controller { MasterEntities db = new MasterEntities(); // GET: /Home/ public ActionResult Index() { return View(); } public JsonResult UpdateState2() { string fileName = &#34;&#34;; for (int i = 0; i &lt; Request.Files.Count; i++) { HttpPostedFileBase postedFile = Request.Files[i]; if (Request.Browser.Browser.ToUpper() == &#34;IE&#34; || Request.Browser.Browser.ToUpper() == &#34;INTERNETEXPLORER&#34;) { string[] file = postedFile.FileName.Split(new char[] { &#39;\\&#39; }); fileName = file[file.Length - 1]; } else { fileName = postedFile.FileName; } postedFile.SaveAs(System.IO.Path.Combine(Server.MapPath(&#34;~/Files/&#34;), fileName)); } Form st = JsonConvert.DeserializeObject&lt;Form&gt;(Request.Form[&#34;details&#34;]); if (!string.IsNullOrEmpty(st.Name)) { int no = Convert.ToInt32(st.Id); var stateList = db.Forms.Where(x =&gt; x.Id == no).FirstOrDefault(); stateList.Name = st.Name; if (!string.IsNullOrEmpty(fileName)) { stateList.Resume = System.IO.Path.Combine(Server.MapPath(&#34;~/Files/&#34;), fileName); } db.SaveChanges(); return Json(db.Forms, JsonRequestBehavior.AllowGet); } else { return Json(&#34;Addition of state unsucessfull !&#34;, JsonRequestBehavior.AllowGet); } } public JsonResult AddState() { string fileName = &#34;&#34;; for (int i = 0; i &lt; Request.Files.Count; i++) { HttpPostedFileBase postedFile = Request.Files[i]; if (Request.Browser.Browser.ToUpper() == &#34;IE&#34; || Request.Browser.Browser.ToUpper() == &#34;INTERNETEXPLORER&#34;) { string[] file = postedFile.FileName.Split(new char[] { &#39;\\&#39; }); fileName = file[file.Length - 1]; } else { fileName = postedFile.FileName; } postedFile.SaveAs(Path.Combine(Server.MapPath(&#34;~/Files/&#34;), fileName)); } Form st = JsonConvert.DeserializeObject&lt;Form&gt;(Request.Form[&#34;details&#34;]); if (!string.IsNullOrEmpty(st.Name)) { Form state = new Form(); state.Name = st.Name; state.Resume = System.IO.Path.Combine(Server.MapPath(&#34;~/Files/&#34;), fileName); //state.Resume = fileName; db.Forms.AddObject(state); db.SaveChanges(); return Json(db.Forms, JsonRequestBehavior.AllowGet); } else { return Json(&#34;Addition of state unsucessfull !&#34;, JsonRequestBehavior.AllowGet); } } public JsonResult getEmployeeByNo(string id) { try { int no = Convert.ToInt32(id); var employeeList = db.Forms.Where(x =&gt; x.Id == no); return Json(employeeList, JsonRequestBehavior.AllowGet); } catch (Exception exp) { return Json(&#34;Error in getting record !&#34;, JsonRequestBehavior.AllowGet); } } public JsonResult getAll1() { try { var employeeList = db.Forms; return Json(employeeList, JsonRequestBehavior.AllowGet); } catch (Exception exp) { return Json(&#34;Error in getting record !&#34;, JsonRequestBehavior.AllowGet); } } }</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://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css&#34; /&gt; &lt;script type=&#34;text/javascript&#34; src=&#34;https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.8/angular.js&#34;&gt;&lt;/script&gt; &lt;script type=&#34;text/javascript&#34; src=&#34;https://cdn.jsdelivr.net/npm/angular-utils-pagination@0.11.1/dirPagination.js&#34;&gt;&lt;/script&gt; &lt;script type=&#34;text/javascript&#34; src=&#34;https://cdnjs.cloudflare.com/ajax/libs/danialfarid-angular-file-upload/12.2.13/ng-file-upload.min.js&#34;&gt;&lt;/script&gt; &lt;script type=&#34;text/javascript&#34;&gt; var app = angular.module(&#34;MyApp&#34;, [&#39;ngFileUpload&#39;, &#39;angularUtils.directives.dirPagination&#39;]); app.controller(&#34;MyController&#34;, [&#39;$scope&#39;, &#39;$http&#39;, &#39;myService&#39;, function ($scope, $http, myService) { $scope.mahesh = false; GetAllTerms(); function GetAllTerms() { var getData = myService.getterms(); getData.then(function (tc) { $scope.terms = tc.data; }, function (tc) { alert(&#34;Records gathering failed!&#34;); }); } $scope.UploadFiles = function (files) { $scope.SelectedFiles = files; }; //edit by id $scope.editState = function (state) { GetAllTerms(); $scope.mahesh = true; var getData = myService.getState(state.Id); getData.then(function (emp) { $scope.Id = emp.data[0].Id; $scope.Name = emp.data[0].Name; $scope.Resume = emp.data[0].Resume.split(&#39;\\&#39;)[emp.data[0].Resume.split(&#39;\\&#39;).length - 1]; $scope.Action = &#34;Edit&#34;; }, function (msg) { //$(&#34;#alertModal&#34;).modal(&#39;show&#39;); alert(msg.data); $scope.msg = msg.data; }); //$scope.$apply(); } $scope.AddUpdateEmployee = function () { $scope.mahesh = $scope.mahesh; var getAction = $scope.Action; if (getAction == &#34;Edit&#34;) { var formData = new FormData(); var files = $scope.SelectedFiles; if (files != undefined) { for (var i = 0; i &lt; files.length; i++) { formData.append(files[i].name, files[i]); } } var details = {}; details.Name = $scope.Name; details.Id = $scope.Id; formData.append(&#34;details&#34;, JSON.stringify(details)); var getData = myService.updateSta(formData); getData.then(function (tc) { $scope.terms = tc; }, function (msg) { alert(msg.data); $scope.msg = msg.data; }); } else { var formData = new FormData(); var files = $scope.SelectedFiles; if (files != undefined) { for (var i = 0; i &lt; files.length; i++) { formData.append(files[i].name, files[i]); } } var details = {}; details.Name = $scope.Name; formData.append(&#34;details&#34;, JSON.stringify(details)); var getData = myService.AddSt(formData); getData.then(function (tc) { $scope.terms = tc; }); } } $scope.AddStateDiv = function () { $scope.mahesh = $scope.mahesh ? false : true; $scope.Action = &#34;Add&#34;; } } ]); app.service(&#34;myService&#34;, function ($http) { //get All countries this.getterms = function () { return $http.get(&#34;/Home/getAll1&#34;); }; // get Employee By Id this.getState = function (employeeID) { var response = $http({ method: &#34;post&#34;, url: &#34;/Home/getEmployeeByNo&#34;, params: { id: JSON.stringify(employeeID) } }); return response; } this.AddSt = function (employee) { var response = $.ajax({ url: &#39;/Home/AddState&#39;, type: &#34;POST&#34;, contentType: false, processData: false, data: employee }); return response; } this.updateSta = function (employee) { var response = $.ajax({ url: &#34;/Home/UpdateState2&#34;, type: &#34;POST&#34;, contentType: false, processData: false, data: employee }); return response; } }); &lt;/script&gt; &lt;/head&gt; &lt;body ng-app=&#34;MyApp&#34; ng-controller=&#34;MyController&#34;&gt; &lt;div class=&#34;container&#34;&gt; &lt;div id=&#34;wrapper&#34; class=&#34;clearfix&#34; ng-show=&#34;mahesh&#34;&gt; &lt;form name=&#34;userForm&#34; novalidate&gt; &lt;h4 class=&#34;modal-title&#34; style=&#34;text-align: center;&#34;&gt;{{Action}} State Details&lt;/h4&gt; &lt;div class=&#34;form-horizontal&#34;&gt; &lt;div class=&#34;form-row&#34;&gt; &lt;div class=&#34;col-md-4&#34;&gt; &lt;label for=&#34;COI_Name&#34;&gt;Upload a file&lt;/label&gt; &lt;input type=&#34;file&#34; ngf-select=&#34;UploadFiles($files)&#34; /&gt; &lt;/div&gt; &lt;div&gt; &lt;div class=&#34;col-md-4&#34;&gt; &lt;label for=&#34;Name&#34;&gt;Name&lt;/label&gt; &lt;input type=&#34;text&#34; class=&#34;form-control&#34; name=&#34;Name&#34; ng-model=&#34;Name&#34; placeholder=&#34;Enter State Name&#34; required /&gt; &lt;span&gt;{{Resume}}&lt;/span&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class=&#34;form-group&#34;&gt; &lt;/div&gt; &lt;div class=&#34;form-group&#34; style=&#34;width: 120%; text-align: center; padding: 10px;&#34;&gt; &lt;div class=&#34;col-md-offset-2 col-md-5&#34;&gt; &lt;p&gt; &lt;button class=&#34;btn btn-success btn-sm&#34; ng-model=&#34;IsVisible&#34; ng-click=&#34;AddUpdateEmployee()&#34;&gt; &lt;span class=&#34;glyphicon glyphicon-ok&#34;&gt;&lt;/span&gt;Submitt &lt;/button&gt; &lt;button class=&#34;btn btn-danger btn-sm&#34; ng-click=&#34;close()&#34;&gt; &lt;span class=&#34;glyphicon glyphicon-remove&#34;&gt;&lt;/span&gt;Close &lt;/button&gt; &lt;/p&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/form&gt; &lt;/div&gt; &lt;button class=&#34;btn btn-success btn-sm &#34; ng-click=&#34;AddStateDiv();&#34; style=&#34;margin-left: 15px;&#34;&gt;Add Country&lt;/button&gt; &lt;hr style=&#34;width: 550px;&#34; /&gt; &lt;div id=&#34;dvContainer&#34;&gt; &lt;div&gt; &lt;div class=&#34;table-responsive &#34; style=&#34;overflow-x: auto;&#34;&gt; &lt;table id=&#34;dvData&#34; cellpadding=&#34;12&#34; class=&#34;table table-bordered table-hover table-striped&#34; style=&#34;margin-left: 20px; margin-right: 20px;&#34;&gt; &lt;tr class=&#34;success&#34;&gt; &lt;th&gt;Id&lt;/th&gt; &lt;th&gt;File&lt;/th&gt; &lt;th&gt;Name&lt;/th&gt; &lt;th&gt;Actions&lt;/th&gt; &lt;/tr&gt; &lt;tr dir-paginate=&#34;state in terms |orderBy:sortKey:reverse|itemsPerPage:10&#34; ng-model=&#34;search&#34;&gt; &lt;td&gt;{{state.Id}}&lt;/td&gt; &lt;td&gt;{{state.Resume.split(&#39;\\&#39;)[state.Resume.split(&#39;\\&#39;).length-1]}}&lt;/td&gt; &lt;td&gt;{{state.Name }}&lt;/td&gt; &lt;td&gt;&lt;button type=&#34;button&#34; class=&#34;btn btn-default btn-sm&#34; ng-click=&#34;editState(state)&#34; &gt;Edit&lt;/button&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/div&gt; &lt;/div&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/A0hjMp7.gif" alt="" width="270" height="498" /></p>https://www.aspforums.net:443/Threads/184867/Display-File-Name-on-Edit-Button-Click-using-AngularJS-in-ASPNet-MVC/https://www.aspforums.net:443/Threads/184867/Display-File-Name-on-Edit-Button-Click-using-AngularJS-in-ASPNet-MVC/Fri, 16 Aug 2019 05:42:14 GMT