MVC2에서는 게시 할 때 강력하게 형식화 된 뷰를 만들 때 FormCollection 개체를 사용하지 않았습니다. 내 서명이 항상처럼 보였다 :TryUpdateModel 대 강력한 형식의 메서드 매개 변수 대
[AcceptVerbs(HttpVers.Post)]
public Create(Person newPerson)
{
//code to update the person from the post
}
하지만 지금 난 그냥 같은 것을 작성합니다 새로운 TryUpdateModel 방법보고 있어요 :
[AcceptVerbs(HttpVers.Post)]
public Create()
{
Person thePersonToCreate = new Person()
TryUpdateModel(thePersonToCreate)
{
//Code to create the person if model is valid
}
}
것은 그래서 지금은 내가 모의해야 할 것 같습니다 HttpContext를 이 메소드를 테스트하기 위해서. 그러나 강력한 형식의 메서드를 사용하여 이전 방법을 사용할 수있는 것처럼 보입니다. TryUpdateModel 메서드는 작업을 수행하는 FormCollection 메서드를 사용하지만 TryUpdateModel을 사용해야하는 이유는 무엇인지 깨달았습니다.