i have developed a web application using asp.net mvc4 and razor syntax. i need to upload an image using file uploader and display in the same page with details of the image.
as an example there's a "file uploader"
and "submit button"
in "contact page"
of my application. when i upload an image of a person and click
the submit button, it should display the image somewhere in the page with its details like image name, size like that.
is there any possible way to achieve that?
here is the code for my controller class
public class FileUploadController : Controller
{
//
// GET: /FileUpload/
public ActionResult Index()
{
return View();
}
public ActionResult FileUpload()
{
return View();
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult FileUpload(HttpPostedFileBase uploadFile)
{
if (uploadFile.ContentLength > 0)
{
string filePath = Path.Combine(HttpContext.Server.MapPath("~/Img/"),
Path.GetFileName(uploadFile.FileName));
}
return View();
}
}
and here is the code for view
<h2>FileUpload</h2>
@(Html.BeginForm("FileUpload", "FileUpload",FormMethod.Post, new { enctype = "multipart/form-data" }))
<input name="uploadFile" type="file" />
<input type="submit" value="Upload File" />
but how to display on page?
please help.
is there any possible way to achieve that?
- yes, of course. Where did you get so far? What research you did and what code did you attempt to write? What difficulties did you encounter with this code that you would like to ask about? – Humor