ASP.NET Mobile View中的FormCollection为空

时间:2016-10-03 13:43:56

标签: c# asp.net asp.net-mvc formcollection

当我将此代码用作网络视图时,它运行正常,但是当Chrome浏览器中使用开发者选项时,我选择移动视图,FormCollection在控制器中显示空字符串

查看(编辑更新)

<div class="page product-details-page deal-product-details-page">
    @using (Html.BeginForm("AddProductToCart_Details", "DealProduct", new { productId = Model.Id, shoppingCartTypeId = 1 }, FormMethod.Post))
    {
        <div class="page-body">

            @using (Html.BeginRouteForm("Product", new { SeName = Model.SeName }, FormMethod.Post, new { id = "product-details-form" }))
            {
                            @{
                                var dataDictAttributes = new ViewDataDictionary();
                                dataDictAttributes.TemplateInfo.HtmlFieldPrefix = string.Format("attributes_{0}", Model.Id);
                                @Html.Partial("~/Views/Product/_ProductAttributes.cshtml", Model.ProductAttributes, dataDictAttributes)

                            }
                            <!--gift card-->
                            @{
                                var dataDictGiftCard = new ViewDataDictionary();
                                dataDictGiftCard.TemplateInfo.HtmlFieldPrefix = string.Format("giftcard_{0}", Model.Id);
                                @Html.Partial("~/Views/Product/_GiftCardInfo.cshtml", Model.GiftCard, dataDictGiftCard)

                            }
                            <!--rental info-->
                            @{
                                var dataDictRental = new ViewDataDictionary();
                                dataDictRental.TemplateInfo.HtmlFieldPrefix = string.Format("rental_{0}", Model.Id);
                                @Html.Partial("~/Views/Product/_RentalInfo.cshtml", Model, dataDictRental)

                            }
                            <!--price & add to cart-->
                            @{
                                var dataDictPrice = new ViewDataDictionary();
                                dataDictPrice.TemplateInfo.HtmlFieldPrefix = string.Format("price_{0}", Model.Id);
                                @Html.Partial("~/Views/Product/_ProductPrice.cshtml", Model.ProductPrice, dataDictPrice)


                                @Html.Partial("~/Views/Product/_ProductTierPrices.cshtml", Model.TierPrices)
                            }
                            <!--wishlist, compare, email a friend-->

                                    <!--attributes-->
                                    @{
                                        var item = @Model.AssociateProductAttributesList.Where(x => x.Item1 == data.Id).Select(x => x.Item2).ToList()[0];
                                        bool isAttributes =false;
                                    }

                                    <div class="popup" data-popup="popup-@data.Id">
                                        <div class="popup-inner">
                                            <h2>@data.Name</h2>
                                            <p>@data.ShortDescription</p>

                                            <br />
                                            @foreach (System.Collections.DictionaryEntry value in item)
                                            {
                                                var val = data.Id + "_" + value.Key.ToString();

                                                isAttributes = true;
                                                @*<div class="attributes">*@
                                                <dl>
                                                    <dt id="product_attribute_label_19">
                                                        <label class="text-prompt">
                                                            @value.Key.ToString()
                                                        </label>
                                                    </dt>
                                                    <dd id="product_attribute_input_19" class="product_attribute_inputdiv_@val">
                                                        @Html.DropDownList("Attributes," + data.Id + "," + value.Key.ToString(), new SelectList((System.Collections.IEnumerable)value.Value, "Id", "Name"), "--- Please select ---")

                                                    </dd>
                                                </dl>
                                                @*</div>*@
                                            }
                                            <br />
                                            <div onclick="ImageBlur('div_@data.Id')" class="buttons" style="text-align:left;">
                                                <input class="button-1" data-popup-close="popup-@data.Id" type="button" value="Add to back" />
                                            </div>

                                            <a class="popup-close" data-popup-close="popup-@data.Id" href="#">x</a>
                                        </div>
                                    </div>
                                    @if (item.Count == 0)
                                    {
                                        @Html.Hidden("Attributes," + data.Id + ",", "0")
                                        <div class="popup" data-popup="popup-@data.Id">
                                            <div class="popup-inner">
                                                <h2>@data.Name</h2>
                                                <p>@data.ShortDescription</p>


                                                <div onclick="ImageBlur('div_@data.Id')" class="buttons" style="text-align:left;">
                                                    <input class="button-1" data-popup-close="popup-@data.Id" type="button" value="Add to back" />
                                                </div>


                                                <a class="popup-close" data-popup-close="popup-@data.Id" href="#">x</a>
                                            </div>
                                        </div>
                                    }



                                @if (isAttributes)
                                {
                                    <a style="color: blue;" data-popup-open="popup-@data.Id" href="#">
                                        <img id="imgdiv_@data.Id" src="~/Themes/Playground/Content/img/dealselectattribut.png" class="select-atr-img" style="width: 50%; margin-bottom: 10px;"/>
                                    </a>
                                }
                            </div>
                         }


                    </div>

                    <div>

                    </div>
                    @{
                        var dataDictAddToCart = new ViewDataDictionary();
                        dataDictAddToCart.TemplateInfo.HtmlFieldPrefix = string.Format("addtocart_{0}", Model.Id);
                        <div class="overview" style="width:100%; margin-left:auto">

                            @Html.Partial("~/Views/Product/_AddToCart.cshtml", Model.AddToCart, dataDictAddToCart)

                        </div>
                    }


                </div>
                        }

        </div>
                        }
</div>

控制器

 public ActionResult AddProductToCart_Details(int productId, int shoppingCartTypeId, FormCollection form)
        {

            if (_productService.IsDealProducts(productId))
            {
                if (!IsCompleteSelected(form))
                {
                    return Json(new
                    {
                        success = false,
                        message = "    Plese select all associated product attribute    "
                    });
                }
            }
//more code here
}

普通视图(Web视图) enter image description here

移动视图

enter image description here

1 个答案:

答案 0 :(得分:3)

不允许使用表格。这是你的问题。