문제

부분보기를 사용하고 싶은 시나리오가 있지만 데이터를 컨트롤러로 전달하는 데 문제가 있습니다. 다음은 내가하려는 일의 기본 예입니다.

사물:

  • 고객
  • 주문하다

고객은 다음과 같습니다 IList<Order> 그 위에. 부분적인보기가 사용자가 정보를 편집 할 수 있도록합니다. 데이터를 표시 할 수 있지만 양식이 게시되면 고객 객체 아래의 목록이 NULL입니다.

나는 또한 부분적인 관점에서 별도의 형태를 사용하려고 시도했다. 컨트롤러에서 파라멘터를 생성하면 데이터를 얻을 수 있습니다.

public ActionResult UpdateOrders(IList<Guid> id, IList<int> quantity, IList<Guid> productId)

그러나 내가 이것을 할 때

public ActionResult UpdateOrders(IList<Order> orders)

목록은 null입니다.

누군가가이를 달성하는 방법에 대한 더 나은 제안을한다면 알려주세요.

도움이 되었습니까?

해결책

당신의 견해에서 필드를 어떻게 참조하고 있습니까? 나는 그것이 다음과 같아야한다고 생각합니다.

<input type="hidden" name="orders.Index" value="0" />
<input type="hidden" name="oders[0].ID" value="1" />
<input type="hidden" name="orders[0].productId" value="4" />
<input type="text" name="orders[0].quantity" value="6" />

<input type="hidden" name="orders.Index" value="1" />
<input type="hidden" name="orders[1].ID" value="2" />
<input type="hidden" name="orders[1].productId" value="2" />
<input type="text" name="orders[1].quantity" value="15" />

Phil Haack의 블로그 항목을 참조하십시오 목록에 바인딩 더 많은 정보를 위해서.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top