c# - ASP.NET 移动 View 中的 FormCollection 为空

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

当我将此代码用作 Web View 时,它工作正常,但是当我在 Chrome 中使用开发人员选项时,我选择移动 View ,FormCollection 在 Controller 中显示空字符串

查看(编辑更新)

<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>

Controller

 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
}

普通 View (网页 View ) enter image description here

移动 View

enter image description here

最佳答案

表单中的表单是不允许的。这是你的问题。

关于c# - ASP.NET 移动 View 中的 FormCollection 为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39833165/

相关文章:

c# - 如何让 T4 基于特定命名空间中的类生成代码(递归)

c# - 我在非静态方法上收到 "an object reference is required for the non-static field"异常...我做错了什么?

asp.net - 单独验证 Div 标签

c# - Entity Framework 6 将自定义 SQL 查询映射到实体

asp.net-mvc - 如何创建功能类似于 Webforms Wizards 的 MVC 'Wizard'?

asp.net-mvc - ASP.NET MVC 路由 : how to use routing over matching files for a single folder?

c# - 在被动 View 架构中,我应该在哪里为 Presenter 类创建依赖项?

c# - ASP.NET DateTime.Now 错误的时间

c# - 从转发器中的下拉列表更新用户角色

c# - 如何从 myclass 绑定(bind) CheckBox?