【问题标题】:Strange issue while including Scripts in MVC razor在 MVC razor 中包含脚本时出现奇怪的问题
【发布时间】:2016-12-07 14:58:26
【问题描述】:

我以前开发过 mvc 应用程序。我目前正在开发基于 cRUd 的应用程序。我必须使用 JQuery Bootgrid。基础架构是 VS 2013。MVC 5。但是,当我在表上调用 bootgrid 函数时,表不会被渲染,只有搜索插件出现在屏幕上。在 chrome 中调试时,我在脚本声明后看到一些错误符号。我一无所知,任何建议都会有所帮助。

我正在附加我的代码以及来自 chrome 的屏幕图像。

 @model COE.Tools.Adapt.DataTransferObjects.ViewModels.UserProfileViewModel

@{
    ViewBag.Title = "Manage User Information";
}

<div class="row">
    <div class="col-lg-12">
        <h2 class="sub-header">ManageUsers</h2>
    </div>
    <!-- /.col-lg-12 -->
</div>

<div class="row">
    <div class="panel panel-default">
        <div class="panel-heading">
            <div class="row">
                <div class="col-lg-2 col-md-3">
                    <i class="fa fa-user fa-3x" aria-hidden="true"></i>
                    <button id="btnAddNew" value="NewUser" class="btn btn-default">NewUser</button>
                </div>
            </div>
        </div>
        <div class="panel-body">
            <div class="row">
                <div class="col-lg-12 col-md-12">
                    <table id="gridUsers" class="table table-bordered table-hover">
                        <thead>
                            <tr id="tbHeader">
                            <tr>
                                <th data-column-id="firstName">FirstName</th>
                                <th data-column-id="lastName">LastName</th>
                                <th data-column-id="userId">UserId</th>
                                <th data-column-id="email">Email</th>
                                <th data-column-id="role">Role</th>
                                <th data-column-id="app">Applications</th>
                                <th data-column-id="plant">Plant</th>
                                <th data-formatter="Edit">Edit</th>
                                <th data-formatter="Delete">Delete</th>
                            </tr>
                        </thead>
                        <tbody>
                            @{
                                foreach (var vm in Model.lstUserInformation)
                                {
                                    <tr>
                                        <td>@vm.FirstName</td>

                                        <td>@vm.LastName</td>

                                        <td>@vm.UserId</td>

                                        <td>@vm.Email</td>
                                        <td>@vm.RoleDescription</td>
                                        <td>@vm.UserApplication</td>
                                        <td>@vm.DefaultLocation</td>
                                        <td>
                                            <a id="idEditUser" href="@Url.Action("EditUser", "Account", new  {@userId = @vm.UserId })"><i class="fa fa-pencil-square-o fa-2x" aria-hidden="true"></i> Edit </a>
                                        </td>
                                        <td>
                                            <a id="idDeleteUser" href="@Url.Action("DeleteUser", "Account", new {@userId = @vm.UserId  })"><i class="fa fa-trash fa-2x" aria-hidden="true"></i> Delete </a>
                                        </td>
                                    </tr>

                                }
                            }
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>


@section MyScripts {


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

            alert('opk');
            $("#gridUsers").bootgrid({
                caseSensitive: false,
                sorting: true,
                multiSort: true,
                selection: true,
                rowSelect: true,
                multiSelect: true,
                keepSelection: true,
                searchSettings: {
                    delay: 100,
                    characters: 1
                },
                labels: {
                    infos: "GridResults",
                    search: "GridSearch",
                    noResults: "GridNoResults",
                    all: "GridAllRowCount",
                    loading: "GridLoading"
                },
                formatters: {

                }
            });
        });
    </script>
}

【问题讨论】:

  • 您确定关闭您的@scripts 部分吗?最后加上}
  • 是的。它完成了。对不起,我错过了复制它。
  • chrome给你的错误是什么?
  • Chrome 没有给出任何错误。否则我会很容易地调试它。它显示红色符号并在渲染后出现 bootgrid 搜索和分页工具。但表格变得不可见。

标签: jquery asp.net-mvc asp.net-mvc-4 razor


【解决方案1】:

找到我的问题。愚蠢的我。我有 2 个 tr,第一个没有数据。

感谢您调查我的问题。

【讨论】:

  • 感谢您的更新。为了将来参考,除非您包含 @name,否则用户不会收到对 cme​​ts 的回复,例如 @user3545750
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-10-04
  • 2017-10-23
  • 1970-01-01
  • 2012-07-26
相关资源
最近更新 更多