在其他部分视图中计算已选中的复选框 [英] count checked checkboxes in other partial view

查看:52
本文介绍了在其他部分视图中计算已选中的复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我想显示检查了多少个复选框。这是我的部分视图,用户可以选择选择框:



 div id =  标签 >  
< ul>
< li>< a href = #tabs-1>个人信息< / a > < span class =code-keyword>< / li >
< li>< a href = #tabs-2>个人资料照片< / a > < / li >
< li>< a href = #tabs-3>其他照片< / a > < / li >
< li>< ; a href = #tabs-4> Climb < / a > < ; / li >
< li>< a href = #tabs-5> route < / a > < / li >
< / ul >
< div id = tabs-1 >
@ Html.Partial( _ GetUserProfile,Model)
< / div >
< div id = tabs-2 >
@ Html.Partial( _ GetProfilePicture,Model)
< / < span class =code-leadattribute> div
>
< div id = tabs-3 >
@ Html.Partial( _ GetOtherImages,型号)
< / div >
< div id = tabs-4 >
@ Html.Partial ( _ GetClimbTab,Model)
< ; / div >

< div id = tabs-5 >
@ Html.Partial( _ GetRouteTab,Model)
< / div >

< / div >

@sect离子脚本
{
< link href = @ Url.Content(〜/ Content / themes / base / jquery-ui.css rel = stylesheet type = text / css />
< link href = @ Url.Content(〜/ Content / Site。 css rel = < span class =code-string> stylesheet type = text / css />
< script src = @ Url.Content( 〜/ Scripts / jquery-1.11.0.min.js) type = text / javascript > < / script >
< script src = @ Url.Content( 〜/ Scripts / jquery.form.js) type = text / javascript > < ; / script >
< script src = @ Url.Content( 〜/ Scripts / jquery-ui-1.10.4.min.js) type = text / javascript > < / script >
< script src = @ Url.Content( 〜/ Scripts / jquery.unobtrusive-ajax.min.js) type = < span class =code-keyword> text / javascript > < / script >
< script src = @ Url.Content( 〜/ Scripts / bootstrap-filestyle.js) 类型 = text / javascript > < / script >
< script < span class =code-attribute> src = @ Url.Content( 〜/ Scripts / jquery.form.min.js) 类型 = text / javascript > < / script >

< script >

$(document).ready(function(){

var numSelected = $( input.mycheckBox:检查)长度;
alert(numSelected)




});





这样有用,你会看到选中了多少个复选框。



但是其他部分视图必须看到多少个复选框,比如这个(detail.cshtml):



< div id =  标签 >  
< ul>
< li>< a href = #tabs-1>个人资料< / a > < / li >
< li>< a href = #tabs-2>照片< / a > < / li >

< / ul >
< div id = tabs-1 >
@ Html.Partial( _ GetDetailsProfileTab,Model)
< / div >
< div id = tabs-2 >
@ Html.Partial( _ GetDetailsPhotoTab,Model)
< / div >


< / div >



@section脚本{

< link href = @ Url.Content(〜/ Content / themes / base / jquery-ui.css rel = stylesheet type = < span class =code-string> text / css />
< link href = @ Url.Content(〜/ Content / Site。 css rel = < span class =code-string> stylesheet type = text / css />
< link href = @ Url.Content(〜/ Content / Progressbar。 css rel = < span class =code-string> stylesheet type = text / css />

< script src = @ Url.Content( 〜/ Scripts / jquery-ui-1.10.4.min.js) type = text / javascript > < / script >
< script src < span class =code-keyword> = @ Url.Content( 〜/ Scripts / Progressbar .js) type = text / javascript > < / 脚本 >






< script >

$(document).ready(function(){

var numSelected = $( input.meter:checked)。length;
alert(numSelected)




});





因为这是详细视图,用户可以看到所有其他用户以及哪个用户选择了哪个复选框。



这是例如部分的_GetDetailsProfileTab视图:





< div> 
< div class = table-响应 >
< table class = table table-striped table-bordered >
< tr>

< th>< h4> Climbs < / h4 < span class =code-keyword>> < div id = progressBar class = climbsName> < div> < / div > < / div > < / th >

< / tr >

< tr>

< td>
< table width = 550 >
< tr>
< td>< h6> NAME < / h6 > < / td >

< td>< h6> COUNTRY < / h6 > < / td >

< td>< h6> DIFFICULT LEVEL < / h6 > < / td >

< / tr >



@ {
foreach var climb Model.Climbs)
{


< tr>
< td> @ climb.Name < / td >

< td> @ climb.country.country_name < / td >

< td> @ climb.difficult.DifficultName < / td >

< / tr >



}
}
< / >



< / td >

< / tr >



< / 表格 >

< / div >
< / div >





用户可以通过其他个人资料查看选中的复选框。



但是在Details.cshtml文件中,如果你使用它:



 $(document).ready(function(){

var numSelected = $( input.meter:选中)。length;
alert(numSelected)




});





这个不再有用了。如果每次给出0



谢谢

解决方案

(文件).ready(function(){

var numSelected =


input.mycheckBox:选中)。length;
alert(numSelected)




});





这样可行,你会看到多少个复选框选择。



但是其他部分视图必须看到多少个复选框,如下所示(detail.cshtml):



< div id =   tabs >  
< ul>
< li>< a href = #tabs-1>个人资料< / a > < / li >
< li>< a href = #tabs-2>照片< / a > < / li >

< / ul >
< div id = tabs-1 >
@ Html.Partial( _ GetDetailsProfileTab,Model)
< / div >
< div id = tabs-2 >
@ Html.Partial( _ GetDetailsPhotoTab,Model)
< / div >


< / div >



@section脚本{

< link href = @ Url.Content(〜/ Content / themes / base / jquery-ui.css rel = stylesheet type = < span class =code-string> text / css />
< link href = @ Url.Content(〜/ Content / Site。 css rel = < span class =code-string> stylesheet type = text / css />
< link href = @ Url.Content(〜/ Content / Progressbar。 css rel = < span class =code-string> stylesheet type = text / css />

< script src = @ Url.Content( 〜/ Scripts / jquery-ui-1.10.4.min.js) type = text / javascript > < / script >
< script src < span class =code-keyword> = @ Url.Content( 〜/ Scripts / Progressbar .js) type = text / javascript > < / 脚本 >






< script >


(document).ready(function(){

var numSelected =

Hi everybody,

I want to show how many checkboxes are checked. This is my partial view, where a user can select the selectboxes:

div id="tabs">
    <ul>
        <li><a href="#tabs-1">Personal information</a></li>
        <li><a href="#tabs-2">Profile Photo</a></li>
        <li><a href="#tabs-3">Other Photos</a></li>
        <li><a href="#tabs-4">Climb</a></li>
        <li><a href="#tabs-5">route</a></li>
    </ul>
    <div id="tabs-1">
        @Html.Partial("_GetUserProfile", Model)
    </div>
    <div id="tabs-2">
        @Html.Partial("_GetProfilePicture", Model)
    </div>
    <div id="tabs-3">
        @Html.Partial("_GetOtherImages", Model)
    </div>
    <div id="tabs-4">
        @Html.Partial("_GetClimbTab", Model)
    </div>

    <div id="tabs-5">
        @Html.Partial("_GetRouteTab", Model)
    </div>

</div>

@section Scripts
{
    <link href="@Url.Content("~/Content/themes/base/jquery-ui.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/jquery-1.11.0.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.form.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery-ui-1.10.4.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/bootstrap-filestyle.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.form.min.js")" type="text/javascript"></script>

    <script>
       
        $(document).ready(function () {
           
            var numSelected = $("input.mycheckBox:checked").length;
                alert(numSelected)
            


              
            });



and so this works, you will see how many checkboxes are selected.

but how many checkboxes have to been seen by a other partial view, like this(detail.cshtml):

<div id="tabs">
    <ul>
        <li><a href="#tabs-1">Profile</a></li>
        <li><a href="#tabs-2">Photos</a></li>
        
    </ul>
    <div id="tabs-1">
        @Html.Partial("_GetDetailsProfileTab", Model)
    </div>
    <div id="tabs-2">
        @Html.Partial("_GetDetailsPhotoTab", Model)
    </div>
 

</div>



@section Scripts{

    <link href="@Url.Content("~/Content/themes/base/jquery-ui.css")" rel="stylesheet" type="text/css" />   
    <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/Progressbar.css")" rel="stylesheet" type="text/css" />

    <script src="@Url.Content("~/Scripts/jquery-ui-1.10.4.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/Progressbar.js")" type="text/javascript"></script>






    <script>

        $(document).ready(function () {

            var numSelected = $("input.meter:checked").length;
            alert(numSelected)




        });



because this is the detail view, where the user can see all the other users and also which user selected which checkboxes.

and this is for example part of the the _GetDetailsProfileTab view:


<div>
        <div class="table-responsive">
            <table class="table table-striped table-bordered">
                <tr>

                    <th><h4>Climbs</h4><div id="progressBar" class="climbsName"><div></div></div></th>

                </tr>
               
                <tr>

                    <td>
                        <table width="550">
                            <tr>
                                <td><h6>NAME</h6></td>

                                <td><h6>COUNTRY</h6></td>

                                <td><h6>DIFFICULT LEVEL</h6></td>

                            </tr>



                            @{
                                foreach (var climb in Model.Climbs)
                                {

                                   
                                    <tr>
                                        <td>@climb.Name</td>

                                        <td>@climb.country.country_name </td>

                                        <td>@climb.difficult.DifficultName</td>

                                    </tr>
                           


                                }
                            }
                        </table>

                       

                    </td>

                </tr>



            </table>

        </div>
    </div>



the user can then see by an other profile wich checkboxes are selected.

But in the Details.cshtml file if you use this:

$(document).ready(function () {

           var numSelected = $("input.meter:checked").length;
           alert(numSelected)




       });



this does not work anymore.if gives everytime 0

Thank you

解决方案

(document).ready(function () { var numSelected =


("input.mycheckBox:checked").length; alert(numSelected) });



and so this works, you will see how many checkboxes are selected.

but how many checkboxes have to been seen by a other partial view, like this(detail.cshtml):

<div id="tabs">
    <ul>
        <li><a href="#tabs-1">Profile</a></li>
        <li><a href="#tabs-2">Photos</a></li>
        
    </ul>
    <div id="tabs-1">
        @Html.Partial("_GetDetailsProfileTab", Model)
    </div>
    <div id="tabs-2">
        @Html.Partial("_GetDetailsPhotoTab", Model)
    </div>
 

</div>



@section Scripts{

    <link href="@Url.Content("~/Content/themes/base/jquery-ui.css")" rel="stylesheet" type="text/css" />   
    <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/Progressbar.css")" rel="stylesheet" type="text/css" />

    <script src="@Url.Content("~/Scripts/jquery-ui-1.10.4.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/Progressbar.js")" type="text/javascript"></script>






    <script>


(document).ready(function () { var numSelected =


这篇关于在其他部分视图中计算已选中的复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆