var file1 = $(this).file[0];
@using (@Html.BeginForm("uploadProductImage", "SellereLogin", FormMethod.Post, new { enctype = "multipart/form-data" })) { <table id="listOfProduct"> <tr> <th> @Html.DisplayNameFor(model => model.ProductId) </th> <th> @Html.DisplayNameFor(model => model.Image1Id) </th> <th> @Html.DisplayNameFor(model => model.Image2Id) </th> <th> @Html.DisplayNameFor(model => model.Image3Id) </th> <th> @Html.DisplayNameFor(model => model.Image4Id) </th> <th></th> </tr> @foreach (var item in Model) { <tr> <td> @Html.DisplayFor(modelItem => item.ProductId) </td> <td> @Html.HiddenFor(m => item.Image1Id) <img src ="@System.Configuration.ConfigurationManager.AppSettings["prodImage"]" class="click"/> </td> <td> @Html.HiddenFor(m => item.Image2Id) <img src ="@System.Configuration.ConfigurationManager.AppSettings["prodImage"]" class="click"/> </td> <td> @Html.HiddenFor(m => item.Image3Id) <img src ="@System.Configuration.ConfigurationManager.AppSettings["prodImage"]" class="click"/> </td> <td> @Html.HiddenFor(m => item.Image4Id) <img src ="@System.Configuration.ConfigurationManager.AppSettings["prodImage"]" class="click"/> @*@Html.ActionLink("Change", "uploadProductImage", new { productId = item.ProductId, imageId = item.Image4Id })*@ </td> </tr> } </table> <div> <input type="file" id="file1" style="display: none" /> </div> }
<script> $(function () { $('.click').on('click', function () { $('#file1').trigger('click'); }); $('#file1').on('change', function () { debugger; var file1 = $(this).file[0]; var formData = new FormData($('form')[0]); $.ajax({ type: "POST", url: "SellereLogin/uploadProductImage", enctype: 'multipart/form-data', data: { file: file1, productId: 123, imageId: 12345 }, success: function () { alert("Data Uploaded: "); } }); }); }); </script>
var file1 = this.file[0];
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)