我想将两个模型传递给视图。并在那里填写这些表格的两个字段。
这是对的吗?
// public ActionResult checkout(string usernam)
//{
// ViewBag.username = usernam;
//using( var db=new myProjectContext())
//{
// var tuple = new Tuple<tbl_Order, tbl_purchase>(new tbl_Order(),new tbl_purchase());
// return View(tuple);
// }
// }
[HttpGet]
public ActionResult checkout(string usernam)
{
ViewBag.username = usernam;
var FeacherToTwoModel = new ViewModelX() ;
return View(FeacherToTwoModel);
}
[HttpPost]
public ActionResult checkout(ViewModelX model)
{
if (ModelState.IsValid)
{
UsersClass.InsertInOrderAndBasket(model.tbl_order.id, model.tbl_ order.id_Type, model.tbl_ order.username,model.tbl_basket.username, model.tbl_basket.id_order);
}
else
{
}
return View();
}
并认为:
// @model Tuple<myProject.Models.tbl_Order, myProject.Models.tbl_purchase>
//<label class="checkbox payment-method inline">
// @Html.CheckBoxFor(tuple => tuple.Item1.TypeCheck)remember me</label>
// .
// .//other fields
// .
.
.
.
<div id="collapseFour" class="accordion-body collapse">
<div class="accordion-inner">
@model MyProject.Models.ViewModelX
<p>please select a style</p>
<label class="checkbox payment-method inline">
@Html.CheckBoxFor(m => m. )remember me </label>
<label class="checkbox payment-method inline">
@Html.CheckBoxFor(m => m. )
online
</label>
<form class="form-inline">
<input class="input-block span4" placeholder="Enter your coupon code here" type="text" id="couponcode">
<button type="submit" class="btn btn-general">register</button>
</form>
</div>
</div>
.
.
.
<tbody>
@model IEnumerable<MyProject.Models.vw_basket>
@foreach (var item in Model)
{
<tr>
<td class="image"><a href='../Kala/Product?NID=@item.id_kala'>
<img '@item.comment' alt='@item.name_product' src="~/Content/Media/Images/product/@MyProject.Models.ProductClass.GetPicById_Product(int.Parse(item.id_Product.ToString()))" width="100"></a></td>
<td class="product"><a href='../Kala/Product?NID=@item.id_ Product ' title='@item.comment'>@item.name_ Product </a> </td>
<td class="stock">@item.number</td>
<td class="price"><s></s> <b>@item.cost </b></td>
<td class="price"><b>@(item.number*item.cost) </b></td>
</tr>
}
<tr>
</tr>
</tbody>
.
.
.
但它无法识别上面的 Item1。(tuple.Item1.TypeCheck)当我发送迁移模型查看并填充它时,tbl_Order 和 tbl_purchase 会填充吗?