Dr.Ajay Kashyap

Dr.Ajay Kashyap

  • NA
  • 521
  • 285.2k

How to Pass Image File and Some Data From Ajax to MVC Contro

Mar 28 2017 10:20 AM

How To pass Image File And Some Data From Using Ajax to Mvc Controller ..i am able to pass from data but image not pass.. What To Do Give Below IS my Code ..

 

This Is Html code :-
<form id="myForm" method="post" enctype="multipart/form-data">
@Html.Label("First Name")
<input class="form-control" id="FirstName" name="FirstName" type="text"/>
@Html.Label("Last Name")
<input class="form-control" id="LastName" name="LastName" type="text"/>
@Html.Label("Email Id")
@Html.TextBox("EmailId", "", new { @class = "form-control", type = "email" })
@Html.Label("Profile Image")
<input type="file" name="ProfileImage" id="ProfileImage" class="form-control" value="ProfileImage">
</form>
 
 
 
This Is My Ajax :-  
 
var myformdata = $("#myForm").serialize();
$.ajax({
type: "POST",
url: "/Business/UserRegistration",
data: myformdata,
success: function () {
$("#loaderDiv").hide();
$("#myModal2").modal("hide");
}
})
 
This Is My Controller :-  
[HttpPost]
public ActionResult UserRegistration(RegistrationViewModel myformdata)
{
 
 
 

Answers (6)