I have a HTML Razor View Like this:
@using (Html.BeginForm("Insert", "Operation", FormMethod.Post, new { @class = "form-horizontal", enctype = "multipart/form-data", id = "image_form" }))
{
<div>
<span class="btn btn-default ">
<span class="fileinput-new">Up Your Image</span>
<input type="file" name="nationalCard" id="nationalCard">
</span>
</div>
<input type="button" class="btn btn-default" id="submit_image" onclick="insert()" value="ثبت" />
}
My Jquery Ajax codes are:
function insert() {
var formData = $("#image_form");
$.ajax({
type: "POST",
url: '@Url.Action("Insert", "Operation")',
data: formData.serialize(),
dataType: "json",
success: function (data) {
//do something...
},
});
};
So I want to receive image in action controller Based on Request object and Files property like this :
[HttpPost]
public ActionResult Insert()
{
if (Request.Files.Count > 0)
{
var image = Request.Files["nationalCard"];
//do something...
}
}
I have tried this and in action didn't receive file.any idea who can I do that?