如果我有一个控制器操作“创建”,它返回一个视图,其中包含以下作为模型类型:
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.
更多推荐
发布评论