Asp.NET MVC查看与不同的对象(Asp.NET MVC View with different objects)

编程入门 行业动态 更新时间:2024-10-24 21:35:55
Asp.NET MVC查看与不同的对象(Asp.NET MVC View with different objects)

如果我有一个控制器操作“创建”,它返回一个视图,其中包含以下作为模型类型:

public class PaymentModel { public Model.SummaryInformation SummaryInformation; public Model.CardDetail CardDetail; }

如果此视图上有一个按钮,则POST为动作“新建”并且我希望该动作接收不同的对象,例如

public class PaymentNewModel { public Model.CardDetail CardDetail; }

这可能吗? 当视图呈现给POST的模型时,我不想使用相同的模型

If i have a controller action "Create" that returns a view with the following as the Model type:

public class PaymentModel { public Model.SummaryInformation SummaryInformation; public Model.CardDetail CardDetail; }

If there is a button on this view that POST's to an action "New" and I want that action to recieve a different object e.g.

public class PaymentNewModel { public Model.CardDetail CardDetail; }

Is this possible? I do not want to use the same Model when the view is rendered to the Model that is POSTed

最满意答案

我不知道会阻止这种情况的任何事情。 动作绑定器并不真正关心,只要它可以解决它。

我假设SummaryInformation对象仅用于演示? (它不会影响输入表单?)在这种情况下,您可以通过ViewData传递它,并直接将视图绑定到CardDetail。 这更接近MVC理念,但可能不是一种方式或者另一种。

I'm not aware of anything that would prevent this. The action binder doesn't really care, as long as it can figure it out.

I assume the SummaryInformation object is only used for presentation? (it does not affect the input form?) In that case, you could pass it via ViewData and just bind the view directly against the CardDetail. This is closer to the MVC philosophy, but probably not a huge deal one way or the other.

更多推荐

本文发布于:2023-08-04 13:25:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1415936.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:对象   NET   Asp   MVC   objects

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!