如何在Controller中获取模型列表

时间:2014-12-01 06:40:28

标签: c# asp.net-mvc-4 razor

我在MVC Razor中有这个表格。 html很长,所以我发布了我想要工作的区域

这些是填充为服务包的复选框

流程是用户将上传照片,当进入下一步时,它将进入一个页面,如果他已经上传3张照片,他将为每张照片选择服务,这三张照片将具有相同的服务

列出但不同的订单IDS

我想要的是,当用户为特定订单选择服务时,意味着特定订单具有多个服务。我想映射它,以便模型列表将在Controller中运行,我可以轻松地插入数据库

这是HTML:

   @using (Html.BeginForm("PlaceOrder", "User", FormMethod.Post, new { id="ServiceForm",@class = "form-horizontal 

white-clr", role = "form" }))
        {
        <!--If user has uploaded a single photo or multiple photo -->

            <div class="window-for-choose-service">
            @if (ViewBag.OrdersList != null)
            {
                int i= 1;


                foreach (var d in ViewBag.OrdersList)
                {
                    <div class="row">

                        <div class="col-sm-3 col-md-3 col-lg-3">
                            <img src="@d.ThumbnailPath" class="img-thumbnail img-responsive" width="250">
                        </div>
                        <div class="col-sm-9 col-md-9 col-lg-9">
                            <form class="white-clr" role="form">
                                <div class="form-group">
                                    <label for="name">Description</label>
                                    <textarea class="form-control" rows="4"></textarea>
                                </div>
                            </form>
                        </div>
                        <div class="col-sm-12 col-md-12 col-lg-12">
                            <div class="panel-group" id="accordion_@d.ID">
                                <div class="panel panel-primary">
                                    @foreach (var Services in ViewBag.ServicePackages)
                                    {
                                        int cID = Services.ID + d.ID;
                                        //int rndNumber = Convert.ToInt32(TimeSpan.FromSeconds(new Random().Next(0, 

11221)).ToString("hmsf"));

                                        if (Services.ServiceParentID == null)
                                        {
                                            <div class="panel-heading">
                                                <h4 class="panel-title">
                                                    <a data-toggle="collapse" data-parent="#accordion_@d.ID"
                                                       href="#collapseOne_@cID">
                                                        @Services.ServiceName
                                                    </a>
                                                </h4>
                                            </div>
    <div id="collapseOne_@cID" class="panel-collapse collapse in">
        <div class="panel-body">
            <div>
                <div class="table-responsive">
                    @foreach (var child in Services.ft_service_packages1)
                    {
                        //string ness = "ServiceSelected[" + @d.ID + "]";
                        <div style="width:auto;min-width:250px;float:left; padding:4px; display:inline-block">
                            <div style="float:left;padding-right:5px;">
                                <label for="inlinecheckbox_@child.ID">
                                    @Html.CheckBoxFor(m => m.ServiceSelect, new { id = "inlinecheckbox_" + 

@child.ID, price_attr = "@child.ServicePrice"})
                                    @Html.HiddenFor(m => m.UploadOrderID, new { Value = @d.ID })
                                </label>
                            </div>
                            <div style="padding-left:2px;">@child.ServiceName</div>
                        </div>

                    }

                </div>
            </div>
        </div>
    </div>
                    i++;
                                        }




                                    }
                                </div>
                            </div>
                        </div>
                        <div class="col-sm-12 col-md-12 col-lg-12"><p class="text-right font-blue"><b> Price $ 

0.0</b></p> </div>
                            </div>

                 }
             }

Html完美无缺。但事情并没有在控制器中获得关于模型的任何内容

模型列在下面

using System;
    using System.Collections.Generic;

    public partial class ft_order_itemized
    {
        public int ID { get; set; }
        public int UploadOrderID { get; set; }
        public int ServiceSelected { get; set; }
        public decimal ServiceCharges { get; set; }
        public System.DateTime ServiceSelectedDate { get; set; }
        public Nullable<int> OrderID { get; set; }
        public bool ServiceSelect { get; set; }

        public virtual ft_orders ft_orders { get; set; }
        public virtual ft_service_packages ft_service_packages { get; set; }
        public virtual ft_uploads_orders ft_uploads_orders { get; set; }
    }

我的控制器:

  [HttpPost]
        public ActionResult PlaceOrder(ICollection<ft_order_itemized> Orders)
        {
            if (Orders.Count > 0)
            { 

            }

           // ICollection Allstrings = Orders["Service"].ToList();           
            return View();
        }

0 个答案:

没有答案