在局部视图中无法响应单选按钮更改

时间:2011-11-22 03:28:34

标签: asp.net asp.net-mvc

我在视图中加载了包含一些radiobuttons的局部视图,但是当我尝试通过单选按钮响应事件时,通过一些jquery调用,我不能。这样做是不可能的,还是我把代码放在错误的地方。我将jquery代码放在View和部分视图类中,但都不起作用。谁能帮忙..有什么建议吗?或代码样本或链接?

以下代码:

抱歉......这是局部视图

@model IEnumerable<Tuda.Models.PriceModel>
<table class="planTable">
        <thead>
            <tr>
                <th></th>
                <th scope="col" abbr="Premium">PREMIUM</th>
                <th scope="col" abbr="Deluxe">DELUXE</th>
                <th scope="col" abbr="Utlmate">ULTIMATE</th>               
            </tr>
        </thead>
        <tfoot>            
            <tr>
                <th scope="row" style="font-weight:bold">Select Plan</th>
                <td><input type="radio" name="planRadio" value="1"></td>
                <td><input type="radio" name="planRadio" value="2"></td>
                <td><input type="radio" name="planRadio" value="3"></td>               
            </tr> 
        </tfoot>
        <tbody>
            <tr>
                <th scope="row">Library Use (Includes Questions & Answers Only)</th>
                <td>Unlimited</td>
                <td>Unlimited</td>
                <td>Unlimited</td>             
            </tr>

            <tr>
                <th scope="row">Interview Tips & Guides</th>
                <td><span ><img src="../../Images/check0.png" /></span></td>
                <td><span ><img src="../../Images/check0.png" /></span></td>
                <td><span ><img src="../../Images/check0.png" /></span></td>               
            </tr>
            <tr>
                <th scope="row">Problem Areas Detection</th>
                <td><span ><img src="../../Images/check0.png" /></span></td>
                <td><span ><img src="../../Images/check0.png" /></span></td>
                <td><span ><img src="../../Images/check0.png" /></span></td>               
            </tr>
             <tr>
                <th scope="row">Relevant Concepts & Terminology</th>
                <td> - </td>
                <td> - </td>
                <td><span ><img src="../../Images/check0.png" /></span></td>               
            </tr>
            <tr>
                <th scope="row">User Recommended</th>
                 <td></td>
                <td><span><img src="../../Images/check0.png" /></span></td>
                <td><span><img src="../../Images/check0.png" /></span></td>             
            </tr>
            <tr>
                <th scope="row">Validity</th>
                <td>1 Month</td>
                <td>3 Months</td>
                <td>12 Months</td>             
            </tr> 
        </tbody>
    </table>  

       <script type="text/javascript">
           $(document).ready(function () {        

$("input[name='planRadio']").change(function(){
    var planse = $("input[name='planRadio']:checked").val();
    $.get('@Url.Action(MVC.Account.AddToCartPartial())',
                { id: planse }, function (data) {
                    $('#plan').html('<p><strong>Adding to cart...</strong>&nbsp;&nbsp;<img src="@Url.Content("~/images/ajax-loader1.gif")" width="54" height="55" /></p>');
                    $("#plan").html(data);
                });

});   
       </script> 

未对控制器进行调用

1 个答案:

答案 0 :(得分:1)

 $(":radio").live("click", function () {
var inputValue = $('input:radio:checked').val(); 
});
or to keep the value of the selected Radiobutton on to hidden field
<input  type="radio" id="SelectedPlanType" rel="1"  name="Plan1" value='1' onClick="document.getElementById('hiddenfield').value=this.value"  checked="checked">
<input type="hidden" name="SelectedPlanType" value="" id="hiddenfield" />