이 원인이 될 수 있습니다 this post
HttpPostedFileBase file = Request.Files["SchoolImageUrl"];
에서 봐 학교에
public ActionResult SchoolCreate(_ASI_School schoolToCreate, FormCollection collection)
{
if (!ModelState.IsValid)
return View();
try
{
// TODO: Add insert logic here
schoolToCreate.SchoolId = Guid.NewGuid().ToString();
schoolToCreate.UserId = new Guid(Request.Form["currentUser"]);
schoolToCreate.SchoolAddedBy = User.Identity.Name;
HttpPostedFileBase file = Request.Files["SchoolImageUrl"];
file.SaveAs(file.FileName);
//schoolToCreate.SchoolImageUrl = Reuseable.ImageUpload(Request.Files["SchoolImageUrl"], Server.MapPath("../Content"));
//schoolToCreate.SchoolImageUrl = Path.GetFullPath(Request.Files[0].FileName);
schoolToCreate.SchoolImageUrl = collection["SchoolImageUrl"];
UpdateModel(schoolToCreate);
_schoolRepository.CreateSchool(schoolToCreate);
//_schoolRepository.SaveToDb();
return RedirectToAction("DepartmentCreate", "Department", new { userId = schoolToCreate.UserId, schoolId = schoolToCreate.SchoolId });
}
catch
{
return View("CreationFailed");
}
}
여기 메신저에 geting 객체 referece 오류를 생성하기위한 컨트롤러를 다음했다. null 값을 얻었는지 확인하기 위해 디버깅을 했습니까?
new { enctype = "multipart/form-data" }
그렇지 않으면 파일 데이터가 POST 요청에 전송되지 않습니다 :
[이 실질적인 예를보십시오] (http://stackoverflow.com/questions/1653469/how-can-i-upload-a-file-and-save-it-to-a-stream-for-further- preview-using-c/1653508 # 1653508) MVC에서 간단한 업로드뿐만 아니라 [이 점을 고려하십시오] (http://stackoverflow.com/questions/851318/asp-net-mvc-1-to-many-saving-post -and-upload-files/851326 # 851326) 나중에 파일을 "첨부"하는 방법에 대해 설명합니다. –