, . "", , "" MSSQL. . , , , AR-15, , .
, : . .
- . , . , . , , , , .
, Profile. - ProfileViewModel ProfileVM. Profile, . , , , SelectList DropDownListFor, , ViewBag .
. - :
public string Photo { get; set; }
public HttpPostedFileBase PhotoUpload { get; set; }
/ PhotoUpload, ( Photo , ).
@Html.TextBoxFor(m => m.PhotoUpload, new { type = "file" })
, :
if (model.PhotoUpload.ContentLength > 0) {
var fileName = Path.GetFileName(model.PhotoUpload.FileName);
var path = Path.Combine(Server.MapPath(uploadPath), fileName);
model.PhotoUpload.SaveAs(path);
model.Photo = uploadPath + fileName;
}
uploadPath , , - ~/uploads/profile/photos. , , , , ( , , ).
- . , - AutoMapper . automapper ( model ProfileViewModel):
var profile = AutoMapper.Mapper.Map<Profile>(model);
, - , , , :
var profile = db.Profiles.Find(userId);
...
Automapper.Mapper.Map(model, profile);
PhotoUpload, Photo. , Photo , , , , - .
, , , , , , , - , Word. if (ModelState.IsValid) :
var validTypes = new[] { "image/jpeg", "image/pjpeg", "image/png", "image/gif" };
if (!validTypes.Contains(model.PhotoUpload.ContentType))
{
ModelState.AddModelError("PhotoUpload", "Please upload either a JPG, GIF, or PNG image.");
}
mime , -.