When I select a file and submit the file for upload, I can't get the value of the File path in my Model. In the Controller it shows as null
. What am I doing wrong?
View
<form method="post" action="/Account/Profile" enctype="multipart/form-data">
<label>Load photo: </label>
<input type="file" name="filePath" id="file" />
<input type="submit" value="submit" />
</form>
Controller
public ActionResult Profile(ProfileModel model, FormCollection form)
{
string path = Convert.ToString(model.FilePath);
return View();
}
Model
public HttpPostedFileBase FilePath
{
get
{
return _filePath;
}
set
{
_filePath = value;
}
}
public bool UploadFile()
{
if (FilePath != null)
{
var filename = Path.GetFileName(FilePath.FileName);
FilePath.SaveAs(@"C:\" + filename);
return true;
}
return false;
}