如何在一个帖子中发布多个模型 [英] How to post multiple models in one post

查看:75
本文介绍了如何在一个帖子中发布多个模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在添加产品的情况下,我希望用户也输入该产品的一些SKU信息.产品和sku有一对一的关系,我想在一个create action post中发布两个模型/对象.一个人将如何实现这一目标?

I have the following scenario of adding a product, I want the user to enter some SKU information for that product as well. The product and sku have a one to one relationship and I want to post two models/objects in one create action post. How would one achieve this?

动作签名看起来像这样

public ActionResult Create(Product product, Sku sku)

要实现此目标,我的剃须刀标记需要什么样?我需要两种形式吗?还是MVC中内置了一些我还没有看到的东西?

what would my razor markup need to look like in order to achieve this? Would I need two forms? Or is there something built into MVC that I haven't seen yet?

推荐答案

您需要另一个包含以下所有必需内容的模型:

You need another model which contains all your required stuff like this:

public Class SomeClassName
{
 public Product product{get;set;}
 public Sku sku{get;set;}
}

然后您需要发送它

public ActionResult Create(SomeClassName data)

这篇关于如何在一个帖子中发布多个模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆