ajaxを使用してフォームを送信しようとしています。フォームには、テキスト フィールドとファイル アップロード フィールドが含まれています。問題は、テキストは送信されますが、ファイルは送信されないことです。私のフォームは
<form onsubmit ="return save();" id="postadform" enctype="multipart/form-data">
Name<input type ="text" name ="name" />
Upload image <input type="file" name="image" id ="filee"/>
<input type ="submit" value = "submit" />
</form>
<script src="~/Scripts/jquery-1.7.1.js"></script>
<script type="text/javascript">
function save() {
$.ajax({
type: 'POST', url: '/Home/saveData', data: $('#postadform').serialize(),enctype:"multipart/form-data",
success: function (x) {
//do what ever you want
},
error: function () {
alert('There is some error, plz try again!');
}
});
return false;
}
</script>
これは HomeController.cs ファイルの一部です。
[HttpPost]
public String saveData()
{
String name = Request["name"];
String filename = Request.Files[0].FileName; //Problem in this line.
return "Successful";
}