2010-06-10 4 views
0

나는 두 개의 create actions..one을 작성하여 작성보기를 호출하고 다른 하나는 httppost를 사용하여 작성보기를 처리합니다.MVC null 모델 문제

내가보기를 호출하면 올바르게 게시되고 드롭 다운이 표시됩니다. 문제는 양식을 작성하고 제출 버튼을 클릭하면 오류가 발생합니다.

개체 참조가 개체의 인스턴스로 설정되지 않았습니다.

첫 번째 생각은 null 모델을 httppost create action에 전달하는 것입니다. null 모델을 전달 액션으로 생성하고 있는지 확인하려면 어떻게해야합니까?

감사합니다.

답변

0

정확히 어디에서 예외가 발생합니까? 컨트롤러 동작 또는 뷰 렌더링 중입니까? 일반적인 패러다임은 다음

public ActionResult New() 
{ 
    // as you will be creating a new entity you don't need to pass 
    // any model here unless your view depends on some property of the model 
    return View(); 
} 

[HttpPost] 
public ActionResult Create(SomeModel model) 
{ 
    // The model parameter here will be automatically instantiated 
    // by the default model binder and its properties will be 
    // initialized to the values entered by the user in the view 
    if (ModelState.IsValid) 
    { 
     // save the entity 
     Repository.Save(model); 
     // redirect back to the index action 
     return RedirectToAction("Index"); 
    } 
    // validation failed => pass the model to the view in order to 
    // preserve values and show validation errors 
    return View("New", model); 
} 
+0

내가 또한 검증 메시지 fire..any를 해달라고 실현 .. 내 modelstate이 invalid..i는 형태로 약 5 필드가 만 2가 선택됩니다 것 같다 이것들에 대한 아이디어? – femi

+1

코드를 게시 할 수 있습니까? –