This example demonstrates how to bind UploadControl (its posted files) to a Model
property.
public ActionResult Index(UserModel modelDTO) {
string fileName = string.Empty;
if (ModelState.IsValid) {
if (modelDTO.Attachment.Length > 0 && modelDTO.Attachment[0].ContentLength > 0) {
fileName = string.Format("~/Content/Files/{0}", modelDTO.Attachment[0].FileName);
modelDTO.Attachment[0].SaveAs(Server.MapPath(fileName));
}
}
SavedModel model = new SavedModel();
model.UserName = modelDTO.UserName;
model.FileUrl = fileName;
return View("Complete", model);
}
- HomeController.cs (VB: HomeController.vb)
- Complete.cshtml (VB: Complete.vbhtml)
- Index.cshtml (VB: Index.vbhtml)
(you will be redirected to DevExpress.com to submit your response)