从 Spark 模板帖子获取 ViewData.Model

发布于 2024-08-10 04:58:41 字数 474 浏览 3 评论 0原文

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

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

在我看来: ${模型.Id} < -- 显示 MyDto.Id

在我尝试执行的服务器上的过滤器中: 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冬天旳寂寞 2024-08-17 04:58:41

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

public ActionResult Action(MyDto dto)
{
   // here dto is filled with values - automatically - if you have corresponding input fields
}

This has nothing to do with Spark or AutoMapper. You need to learn MVC model binders (for example here).

public ActionResult Action(MyDto dto)
{
   // here dto is filled with values - automatically - if you have corresponding input fields
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文