I am working in MVC5, After save the upload image on project folder then I want to bind the image name to model object using hidden field value,
View,
@Html.HiddenFor(m => m.AdImageFileName, new { @id = "hdAdImageFileName" })
What I have tried:
By using jQuery below code, I have saving image and return and bind the image name in to the Hidden field as value.
Advertisement = {
Addform: function (e) {
this.SaveAdvtImages();
$.ajax({
url: "/UserRegister/Advertisement",
type: "POST",
data: $('form').serializeArray(),
success: function (result) {
$('.loading').hide();
$(".modal-content").height(225);
$('#alertMsgModalContent').html(result);
$('#alertMsgModal').modal(options);
$('#alertMsgModal').modal('show');
},
error: function (result) {
}
});
},
SaveAdvtImages: function () {
var formData = new FormData($('#frmAdvertisement')[0]);
$('.loading').show();
$.ajax({
url: '../UserRegister/SaveAdvImages/',
type: 'POST',
data: formData,
contentType: false,
processData: false,
success: function (res) {
$('#hdAdImageFileName').val(res.AdvImage);
},
error: function (data) {
}
});
}
}
But before submit the '
$('form').serializeArray()
' I have to set
m => m.AdImageFileName
model object. Now,
[HttpPost]
public ActionResult Advertisement(AdvertisementVM advertisementVM
{
}
the
advertisementVM.AdImageFileName
is passing null, not setting image name.
Please help me, how can I do this ?