私の理解には助けが必要です!
モデルバインディングをaspコントローラーで使用するのに最適な方法を理解したいと思います。基本的に、セッションでマスターオブジェクト(カート)への参照が必要であり、ユーザーは要求された形式でモデル(editingModel1)を編集します。
基本的に私はこのようなクラスを持つことを考えていました:
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);
}
ユーザーがeditingModel2のような別のものと対話するようにしたい場合は、それもカートに入れる必要があります
これが私の問題を説明することを願っています!
助けてくれてありがとう