이해하는데 도움이 필요합니다.하나 또는 둘 이상의 모델 바인더 모두를 다룰 수있는 모델 바인더?
모델 바인딩이 내 ASP 컨트롤러에서 사용되는 것이 가장 좋은 방법을 알고 싶습니다. 기본적으로 내 세션에서 마스터 객체 (장바구니)에 대한 참조를 원하고 사용자가 요청한 양식으로 모델 (editingModel1)을 편집합니다.
기본적으로이 같은 클래스있는의 생각 : 나는 사용자가 editingModel2 같은 다른 것은 상호 작용하려면public class customModelBinder : IModelBinder {
private const string sessionKey = "Cart";
public object BindModel(ControllerContext controllerContext,
ModelBindingContext bindingContext) {
// get the Cart from the session
Cart cart = (Cart)controllerContext.HttpContext.Session[sessionKey];
// create the Cart if there wasn't one in the session data
if (cart == null) {
cart = new Cart();
controllerContext.HttpContext.Session[sessionKey] = cart;
}
// return the cart
return cart;
}
}
을이
public ActionResult Edit(int id, Cart cb)
{
Company c = _companyProvider.Read(id);
cb.editingModel1 = c
return View(c);
}
처럼 내 컨트롤러에서 사용해야 나도 장바구니에 넣는다
희망이 나의 문제를 설명한다!
어떤 도움을 주셔서 감사합니다.
안녕하세요! 내가 Cart를 사용하는 모델 바인더에 대해 좋아했던 것은 컨트롤러에서 즉시 액세스 할 수 있었고 ID와 같은 추가 변수를 Html.For의 물건으로 클라이언트에 전달할 필요가 없었기 때문입니다. – Nikos
접근 방식 숨겨진 필드를 사용하여 처음에 내가했던 일이었습니다. – Nikos
MVC가 세션을 관리하는 방법을 잘못 이해 한 것 같습니다. 업데이트 된 답변보기 –