Hi,
I am trying to upload file in Ajax.BeginForm() as:
In View:
@using (Ajax.BeginForm("UploadFile","File", null, new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "result" }, new { enctype = "multipart/form-data" }))
{
<label id="lblUploadNewFile" for="fileUploadControl"> Upload New File </label>
<input type="file" name="fileToUpload" id="fileUploadControl" />
<input id="btnFileUpload" type="submit" value="Upload" class="buttongreen" />
<span id="result" />
}
In controller:
[HttpPost]
public string UploadFile(FormCollection formData)
{
HttpPostedFileBase file = null;
try
{
file = Request.Files[0];
}
catch { }
if (file != null && file.ContentLength != 0)
{
file.SaveAs(string.Concat(
AppDomain.CurrentDomain.BaseDirectory,
System.IO.Path.GetFileName(file.FileName)));
return "Successfully Uploaded";
}
else
{
return " Failed, please try again.";
}
}
I am getting failed.
Please help.
Views:
11959
Total Answered:
1
Total Marked As Answer:
0
Posted On:
03-Nov-2015 04:58