I am using asp.net mvc application and trying to upload an image.
This is uploading image function
$(document).ready(function () { TableDatatablesEditable.init(); $("#UploadImg").change(function () { var data = new FormData(); var files = $("#UploadImg").get(0).files; if (files.length > 0) { data.append("MyImages", files[0]); } $.ajax({ url: "@Url.Action("UploadFile")", type: "POST", processData: false, contentType: false, data: data, success: function (response) { $("#HeaderInput").text('/Upload/' + response); $("#imgPreview").attr('src', '/Upload/' + response); }, error: function (er) { alert(er); } }); }); }); Here i am displaying the uploaded image
@Html.Label("Logo Upload", new { @class = "col-md-3 control-label" }) <div class="col-md-7"> <input type="file" class = "col-md-3 control-label" id="UploadImg" value="@Model.FundDetail.ImagePath" name="@Model.FundDetail.ImagePath" /> <br /><br /> <br /> </div> </div> The image uploading is working fine but values are not assigning to the model's property "@Model.FundDetail.ImagePath"
How can i assign value from javascript. Can anyone suggest me how to do this.
Thanks in advance
name="@Model.FundDetail.ImagePath"makes no sense)HttpPostedFileBase Imageand then the file input will be@Html.TextBoxFor(m => m.Image, new { type = "file" })and it will all be correctly bound