In My project I need to upload a text file. We are using MVC4 - Razr. I want to use AJAX/Jquery/Javascript file upload as It doesn't post back to the form. Here is my code. Its actually uploading the file but after that it redirects to reports\uploadfile will the value true. Is there any better way of doing this.
Here is my code @@@@@@@@@
@using (Html.BeginForm("uploadfile", "reports", FormMethod.Post, new {enctype = enter code here`"multipart/form-data"}))
{
<input type="file" name="FileUpload1" /><br/>
<input type="submit" name ="Submit" id="Uploadfile" value="Upload"/>
}
--Controller code
[HttpPost]
public JsonResult UploadReports()
{
if (Request.Files[0].ContentLength > 0)
{
string uploadPath = "C:\\Upload";
string filename = Path.GetFileName(Request.Files[0].FileName);
Request.Files[0].SaveAs(Path.Combine(uploadPath, filename));
}
return Json(true);
}