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.Save multiple records with uploaded file path for single user using AngularJS in ASP.Net MVC<p>Hi&nbsp;mahesh213,</p> <p>You need to save the selected files in an Array. What you are currently using is save only one file.</p> <p>Check the updated script.</p> <pre class="brush: js">&lt;script type=&#34;text/javascript&#34;&gt; var app = angular.module(&#39;MyApp&#39;, [&#39;ngFileUpload&#39;]) app.controller(&#39;MyController&#39;, function ($scope, $window) { $scope.Customers = []; $scope.SelectedFiles = []; $scope.UploadFiles = function (files) { if (files.length &gt; 0) { $scope.SelectedFile = files; $scope.SelectedFiles.push(files); } }; $scope.Add = function () { var customer = {}; customer.Name = $scope.Name; customer.Country = $scope.Country; customer.FileName = $scope.SelectedFile[0].name; $scope.Customers.push(customer); $scope.Name = &#34;&#34;; $scope.Country = &#34;&#34;; }; $scope.Remove = function (index) { var name = $scope.Customers[index].Name; if ($window.confirm(&#34;Do you want to delete: &#34; + name)) { $scope.Customers.splice(index, 1); } } $scope.Save = function () { var orders = {}; orders.EName = $scope.EName; var details = new Array(); for (var i = 0; i &lt; $scope.Customers.length; i++) { var detail = {}; detail.Name = $scope.Customers[i].Name; detail.Country = $scope.Customers[i].Country; details.push(detail); } orders.details = details; var formData = new FormData(); var files = $scope.SelectedFiles; if (files != undefined) { for (var i = 0; i &lt; files.length; i++) { formData.append(files[i][0].name, files[i][0]); } } formData.append(&#34;orders&#34;, JSON.stringify(orders)); $.ajax({ url: &#39;/Home/SaveOrder&#39;, type: &#34;POST&#34;, contentType: false, processData: false, data: formData, success: function (result) { alert(result); $scope.Customers = []; $scope.refresh(); }, error: function (err) { $scope.Message = err.Message; } }); }; }); &lt;/script&gt;</pre> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/550059/Save-multiple-records-with-uploaded-file-path-for-single-user-using-AngularJS-in-ASPNet-MVC/https://www.aspforums.net:443/Threads/550059/Save-multiple-records-with-uploaded-file-path-for-single-user-using-AngularJS-in-ASPNet-MVC/Wed, 31 Jul 2019 03:07:41 GMTSave multiple records with uploaded file path for single user using AngularJS in ASP.Net MVC<p>Based on you file count the loop will be executed.</p> <p>Since you are adding the to Employee object inside the loop the Employee record is inserted multiple times and the&nbsp;EId is set to orderId variable and it is passed to the&nbsp;MultipleUpload object&nbsp;which inserts&nbsp;the new EId to MultipleUploads table.</p> <p>So to overcome the issue declare it outside the loop and insert Employee only once.</p> <p>Check the updated code.</p> <pre class="brush: csharp">[HttpPost] public ActionResult SaveOrder() { string fileName; string result = &#34;Error! Order Is Not Complete!&#34;; { try { // Get Order details from Request object. Employee orders = JsonConvert.DeserializeObject&lt;Employee&gt;(Request.Form[&#34;orders&#34;]); // Do other task. Employee order = new Employee(); order.EName = orders.EName; // Insert to Employee Table. db.Employees.Add(order); db.SaveChanges(); int orderId = order.EId; // Get uploaded files from Request object. if (Request.Files.Count &gt; 0) { 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; } fileName = Path.Combine(Server.MapPath(&#34;~/App_Data/&#34;), fileName); postedFile.SaveAs(fileName); MultipleUpload item1 = orders.details[i]; item1.EId = orderId; item1.FileName = fileName; // Insert to MultipleUpload Table. db.MultipleUploads.Add(item1); db.SaveChanges(); } } result = &#34;Success! Order Is Complete!&#34;; } catch (Exception ex) { return Json(ex.Message, JsonRequestBehavior.AllowGet); } } return Json(result, JsonRequestBehavior.AllowGet); }</pre> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/550059/Save-multiple-records-with-uploaded-file-path-for-single-user-using-AngularJS-in-ASPNet-MVC/https://www.aspforums.net:443/Threads/550059/Save-multiple-records-with-uploaded-file-path-for-single-user-using-AngularJS-in-ASPNet-MVC/Fri, 02 Aug 2019 07:14:55 GMT