I am doing my project in mvc
i have controller to upload file in to a folder
public ActionResult UploadFile(HttpPostedFileBase file)
{
if (ModelState.IsValid)
{
if (file == null) { ModelState.AddModelError("File", "Please Upload Your file"); }
else if (file.ContentLength > 0)
{
.................
else
{ //Excel file copied temporarily to temp folder
var filename = Guid.NewGuid().ToString() + Path.GetExtension(file.FileName);
var path = Path.Combine(Server.MapPath("~/App_Data/Uploads/"), filename);
file.SaveAs(path);
ModelState.Clear();
ViewBag.Message = "File uploaded successfully";
}
}
}
return RedirectToAction("UploadSTR", "Upload");
}
and my view is
@using (Html.BeginForm("UploadFile", "Upload", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
File Path put type="file" name="file" id="file" />
<input type="submit" name="submit" value="Upload" id="btn" />
}
<p> Message:@ViewBag.Message</p>
my problem is that after submit, file is uploaded and the return to the same page .But ViewBag.Message = "File uploaded successfully" is no shown in my view