FormCollection Empty in ASP.NET Mobile View
Asked Answered
C

1

8

When I am using this code as web view, it works fine, but when with developer option in Chrome I select Mobile View, FormCollection shows empty strings in the controller

VIEW (Edit updtaed)

<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="[email protected]">
                                        <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('[email protected]')" class="buttons" style="text-align:left;">
                                                <input class="button-1" data-popup-close="[email protected]" type="button" value="Add to back" />
                                            </div>

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


                                                <div onclick="ImageBlur('[email protected]')" class="buttons" style="text-align:left;">
                                                    <input class="button-1" data-popup-close="[email protected]" type="button" value="Add to back" />
                                                </div>


                                                <a class="popup-close" data-popup-close="[email protected]" href="#">x</a>
                                            </div>
                                        </div>
                                    }



                                @if (isAttributes)
                                {
                                    <a style="color: blue;" data-popup-open="[email protected]" href="#">
                                        <img id="[email protected]" 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
}

Normal View (Web View) enter image description here

Mobile View

enter image description here

Cassock answered 3/10, 2016 at 13:43 Comment(8)
There is not enough information to replicate the issue. Could you create a new project with minimal views and controllers, so that we can replicate it?Poachy
This is the first time I am hearing such issue. Can you post the complete form HTML codeHumidify
its very long... let me minimize itCassock
@Reddy updated the. minimum version, ignore if any bracket is missing I have deleted some content quicklyCassock
Am I seeing double or you really have one form inside of the other one? You know that is not allowed by HTML: https://mcmap.net/q/37408/-is-it-valid-to-have-an-html-form-inside-another-html-form-duplicateHalford
Also, when you post to you form, can you use Fiddler to inspect information submitted? Usually this contains the answerHalford
As @Halford suggested - you have nested form inside a form - or in mvc terms @using(Html.BeginForm... inside another @using(Html.BeginForm.. block, first fix to valid html, then update the question if you're still having an issue (I doubt you will :)).Supposing
form within form works fine in normal view, then whats wrong with mobile view ?Cassock
V
3

Form in form is not allowed. This is your issue.

Viaduct answered 11/10, 2016 at 11:24 Comment(1)
but it is working fine in webview, if it was as issue, it should respond in even webCassock

© 2022 - 2024 — McMap. All rights reserved.