从 Spark 模板帖子获取 ViewData.Model
我正在尝试将我的 Spark 视图转换为使用 ViewData.Model 而不是 namevaluecollection,以便我可以使用 AutoMapper 在进入我的操作方法之前将我的 dto 映射到实体。
我可以从视图访问 viewdata.model,但回发数据后,viewdata.model 为空。这是一些示例代码:
在我看来:
在我尝试执行的服务器上的过滤器中: var model = filterContext.Controller.ViewData.Model;
但 ViewData.Model 为 null。这是在 OnActionExecuted 期间。有没有技巧可以让 ViewData.Model 从发布的视图中获取值?
I am trying to convert my spark views to use ViewData.Model instead of the namevaluecollection so that I can use AutoMapper to map my dto's to entities before it gets into my action method.
I can access the viewdata.model from the view, but upon posting back the data, viewdata.model is null. here is some sample code:
in my view:<viewdata Message="string" model="MyDto" />
${Model.Id} < -- displays MyDto.Id
In my filter on the server I am trying to do:var model = filterContext.Controller.ViewData.Model;
but ViewData.Model is null. This is during OnActionExecuted. Is there a trick to get the ViewData.Model to grab the values from the posted view?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这与 Spark 或 AutoMapper 无关。您需要学习 MVC 模型绑定器(例如 此处)。
This has nothing to do with Spark or AutoMapper. You need to learn MVC model binders (for example here).