0

我正在尝试将我的 spark 视图转换为使用 ViewData.Model 而不是 namevaluecollection,以便我可以使用 AutoMapper 在我的 dto 进入我的操作方法之前将其映射到实体。

我可以从视图访问 viewdata.model,但是在回发数据时, viewdata.model 为空。这是一些示例代码:

在我看来: <viewdata Message="string" model="MyDto" /> ${Model.Id} < -- displays MyDto.Id

在我试图做的服务器上的过滤器中: var model = filterContext.Controller.ViewData.Model;

但 ViewData.Model 为空。这是在 OnActionExecuted 期间。是否有一个技巧可以让 ViewData.Model 从发布的视图中获取值?

4

1 回答 1

0

这与 Spark 或 AutoMapper 无关。您需要学习 MVC 模型绑定器(例如此处)。

public ActionResult Action(MyDto dto)
{
   // here dto is filled with values - automatically - if you have corresponding input fields
}
于 2009-11-06T16:41:25.343 回答