627 users online

How to Get Radio button Checked value from View

Posted: 3 months ago Quote
Hi

I wanted to get Radio button checked value from view to action controller..

My view is

<div class="order-summary-content">

    @if (Model.PublisherSubscriptionSettingsItem.Count > 0)
    {
        using (Html.BeginForm("Subscription", "PublisherSubscription"))
        {
        <table class="cart">
           @* <col  width="1"/>*@
            <col width="1" />
            <col width="1" />
            <col width="1" />
            <thead>
                <tr class="cart-header-row">
                    <th>
                        @T("PublisherSubscriptionSettings.ChoosePlan")
                    </th>
                 <th>
                        @T("PublisherSubscriptionSettings.Plan")
                    </th>
                    <th>
                        @T("PublisherSubscriptionSettings.Price")
                    </th>
                
                   @* <th class="end">
                        @T("ShoppingCart.ItemTotal")
                    </th>*@
                </tr>
            </thead>
            <tbody>          
                @foreach (var item in Model.PublisherSubscriptionSettingsItem)
                {
                    <tr class="cart-item-row">
                    
                    <td>
                    <input id="removefromcart" type="radio" name="removefromcart" value="@(item.Id)" />
                    </td>                      
                            <td style="white-space: nowrap;">
                            <span class="productPrice">@item.SubscriptionPlan</span>
                            </td>

                             <td style="white-space: nowrap;" class="end">
                            <span class="productPrice">@item.Price</span>
                            </td>
                    
                     </tr>
                }
              
            </tbody>
        </table>
          <div class="clear">
        </div>
        
        <div>
        <script language="javascript" type="text/javascript">
            function validateRadioButtonList()
            {

                var radioButtons = document.getElementsByName("removefromcart");
                for (var x = 0; x < radioButtons.length; x++) {
                    if (radioButtons[x].checked) {
                        alert("You checked " + radioButtons[x].id);
                    }
                }
            }
                  </script>

               @* onclick="setLocation('@(@Url.RouteUrl("AddSubscriptionPlanToCart", new { productId = @Model.Id}))')"*@
        <input type="button" value="@T("PublisherSubscription.AddToCart")" ondblclick="javascript:validateRadioButtonList()"/>
        </div>
        }
    }
    
</div>



Please help me in this
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Christopher
Posted: 3 months ago Quote
Replace
<input id="removefromcart" type="radio" name="removefromcart" value="@(item.Id)" />

with
<input id="removefromcart" type="radio" name="removefromcart" value="@(item.Id)"  @(item.IsSelected ? Html.Raw(" checked=\"checked\"") : null) />

P.S. "IsSelected" is new new boolean property of your model indicating whether it should be selected
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Andrei Mazoulnitsyn,
LinkedIn - http://ru.linkedin.com/in/mazoulnitsyn

Twitter - http://twitter.com/#!/nopCommerce
Facebook community page - http://www.facebook.com/pages/NopCommerce/108282972527146
Google+ page - https://plus.google.com/100073150079669136049
Posted: 3 months ago Quote
Hi

Thanks for your replay.. I have bind plan id in radio button, so when user selected any plan.

When i submitted button

<input type="button" value="@T("PublisherSubscription.AddToCart")"  onclick="setLocation('@(@Url.RouteUrl("AddSubscriptionPlanToCart", new { productId = @Model.Id }))')"/>

i want to pass productid(radio button checked value) to controller
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Christopher
Posted: 3 months ago Quote
I would better make a POST request (submit form) instead of your current GET one
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Andrei Mazoulnitsyn,
LinkedIn - http://ru.linkedin.com/in/mazoulnitsyn

Twitter - http://twitter.com/#!/nopCommerce
Facebook community page - http://www.facebook.com/pages/NopCommerce/108282972527146
Google+ page - https://plus.google.com/100073150079669136049
Posted: 3 months ago Quote
hi

i didn't get you.. Please help me its urgent on
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Christopher