显示迁移模型的字段 [英] show migrated model 's fields

查看:46
本文介绍了显示迁移模型的字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将两个模型传递给视图。并填写这些表格的两个字段。



我在下面做了。但是在视野中它不能识别迁移模型的字段。

i表示这一行:@ Html.CheckBoxFor(m => m。)





i wanna pass two models to a view . and fill both fields of these tables , there.

i did below . but in view it dose not recognize migrated model 's fields.
i mean this line: @Html.CheckBoxFor(m => m. )


[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();







查看:






view :

.
      .
      .
     <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_product'>
                                           <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> @item.cost </td>
                                       <td class="price">@(item.number*item.cost) </td>
                                   </tr>
                               }
                               <tr>

                               </tr>
                           </tbody>
                            .
                            .
                            .









calss:







calss :

public class ViewModelX 
        {
            
            public tbl_order   tbl_order { get; set; }
            public tbl_basket   tbl_basket { get; set; }
           

            
        }

推荐答案

创建一个包含所有的新ViewModel类该视图所需的属性。你的错误是你正在放置复杂类型,如tbl_order和tbl_basket。这不是一个好习惯。实际上你需要tbl_order中的一个属性.ViewModels只是包装器,即需要的数据视图。所以将这些属性与课程分开。



希望这有助于
Create a new ViewModel class which contain all the property needed for that view.Your mistake is that you are putting complex type such as tbl_order and tbl_basket.This is not a good practice.Actually you need the one property in the tbl_order.ViewModels are nothing but the wrapper ie, data needed for view. So put that properties separately from the class.

Hope this helps


这篇关于显示迁移模型的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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