Tôi đã điều sau đây:OnActionExecuting thêm vào mô hình trước khi hành động
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
base.OnActionExecuting(filterContext);
if (filterContext == null)
{
throw new ArgumentNullException("filterContext");
}
var model = filterContext.Controller.ViewData.Model as BaseViewModel;
if (model == null)
{
model = new BaseViewModel();
filterContext.Controller.ViewData.Model = model;
}
model.User = (UserPrincipal)filterContext.HttpContext.User;
model.Scheme = GetScheme();
}
Bây giờ bước qua mà tôi có thể nhìn thấy người sử dụng và Đề án mô hình đang được dân cư.
Bởi thời gian tôi nhận được hành động, tuy nhiên cả hai đều là null?
Tôi đang làm gì sai ở đây?
Và thêm vào đây, đây có phải là cách thích hợp để thêm vào mô hình không?
Đây là mã điều khiển:
[InjectStandardReportInputModel]
public ActionResult Header(BaseViewModel model)
{
//by this point model.Scheme is null!!
}
Ông có thể cũng gửi 'Controller' mã của bạn? Bạn chắc chắn bạn đã thêm 'attribute' vào định nghĩa' class' hoặc 'action'/s áp dụng được? – xandercoded
đã thêm mã hành động - bạn có đang nói điều này sẽ hoạt động không? ... – iwayneo
Vấn đề tương tự được thảo luận tại đây http://stackoverflow.com/questions/4766156/all-viewmodels-inherit-from-baseviewmodel-can-i-set -i-up-in-onactionexecut –