在 Jquery 中设置活动手风琴

发布于 2024-07-23 11:52:06 字数 2688 浏览 3 评论 0原文

我将 MVC 与 C# 一起使用,也与 jquery 一起使用。

我正在使用 jquery 手风琴来查看员工详细信息列表。 单击手风琴后,它将显示员工详细信息。

当我单击“编辑员工”时,它将进入“员工详细信息”页面,保存后,会话中将包含 EmployeeDetailsID。 当我回到手风琴页面时,默认情况下应打开包含最后更新员工的手风琴(即,手风琴应根据会话中的 EmployeeDetailsID 打开)。

请建议如何执行此操作。

下面是参考代码。

<html>
<body>
<div class="accordion" id="accordion">
    <%if (Model != null && Model.EmployeeList != null && Model.EmployeeList.Count > 0)
              {
                  foreach (EmployeeDetails _employee in Model.EmployeeList)
                  {
    %>
    <h3>
        <div class="heading_acc">
            <a href="#" onclick="javascript:ShowEmployees(<%= _employee.EmployeeDetailsID %>);"
                id="aEmployee"><b><span class="dash_title_bar_right">
                    <%=Html.Encode(_employee.EmployeeName)%></b> </a>
        </div>
    </h3>
    <div>
        <div id="divReturns<%= _employee.EmployeeDetailsID %>">
            <table width="100%" class="list_contentregion">
                <tr>

                    <th class="dash_table_head">
                        Name
                    </th>
                    <th class="dash_table_head">
                        Role
                    </th>
                    <th class="dash_table_head">
                        Branch
                    </th>
                    <th class="dash_table_head">
                        Last Updated
                    </th>
                </tr>
                <tr id="trEmp<%= _employee.EmployeeDetailsID %>" class="dash_label">

                    <td>
                        <div id="lblName<%= _employee.EmployeeDetailsID %>">
                        </div>
                    </td>
                    <td>
                        <div id="lblRole<%= _employee.EmployeeDetailsID %>">
                        </div>
                    </td>
                    <td>
                        <div id="lblBranch<%= _employee.EmployeeDetailsID %>">
                        </div>
                    </td>
                    <td>
                        <div id="lblTime<%= _employee.EmployeeDetailsID %>">
                        </div>
                    </td>
                </tr>
            </table>
        </div>
    </div>
    <%}
              } %>
</div>

</body>
</html>

I am using MVC with C# also with jquery.

I am using an jquery accordion to see the list of employee details.
On clicking an accordion it'll show the employee details.

When I click Edit of an Employee, it takes to the Employee details page and after save it'll have the EmployeeDetailsID in session. When I come back to the accordion page, the accordion with the last updated employee should be open by default (i.e. Accordion should be open based on the EmployeeDetailsID in session).

Please suggest how to do this.

Below is the code for reference.

<html>
<body>
<div class="accordion" id="accordion">
    <%if (Model != null && Model.EmployeeList != null && Model.EmployeeList.Count > 0)
              {
                  foreach (EmployeeDetails _employee in Model.EmployeeList)
                  {
    %>
    <h3>
        <div class="heading_acc">
            <a href="#" onclick="javascript:ShowEmployees(<%= _employee.EmployeeDetailsID %>);"
                id="aEmployee"><b><span class="dash_title_bar_right">
                    <%=Html.Encode(_employee.EmployeeName)%></b> </a>
        </div>
    </h3>
    <div>
        <div id="divReturns<%= _employee.EmployeeDetailsID %>">
            <table width="100%" class="list_contentregion">
                <tr>

                    <th class="dash_table_head">
                        Name
                    </th>
                    <th class="dash_table_head">
                        Role
                    </th>
                    <th class="dash_table_head">
                        Branch
                    </th>
                    <th class="dash_table_head">
                        Last Updated
                    </th>
                </tr>
                <tr id="trEmp<%= _employee.EmployeeDetailsID %>" class="dash_label">

                    <td>
                        <div id="lblName<%= _employee.EmployeeDetailsID %>">
                        </div>
                    </td>
                    <td>
                        <div id="lblRole<%= _employee.EmployeeDetailsID %>">
                        </div>
                    </td>
                    <td>
                        <div id="lblBranch<%= _employee.EmployeeDetailsID %>">
                        </div>
                    </td>
                    <td>
                        <div id="lblTime<%= _employee.EmployeeDetailsID %>">
                        </div>
                    </td>
                </tr>
            </table>
        </div>
    </div>
    <%}
              } %>
</div>

</body>
</html>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

偷得浮生 2024-07-30 11:52:06

当您编辑员工数据时,我希望您将用户返回到员工列表中的正确页面。

在此假设下,当您循环遍历员工列表时,您可以根据会话变量检查 _employee.EmployeeDetailsID 值,然后将循环迭代次数写入

$("#accordion").accordion( 'activate' , loopIndex);

可以在此处找到 jQuery 手风琴的文档以及此方法的详细信息 http:// docs.jquery.com/UI/Accordion#method-activate

请注意我读过的其他文档,我认为您不应该将会话变量用于此类事情。

我建议通过 MVC 路由系统将变量作为路由值返回。 请参阅以下代码作为示例。

new { Controller = "Employee", Action = "List", Page = pageNumber, EmployeeId = EmployeeDetailsID }

When you're editing your employee data I expect you're returning the user back to the correct page in your employee list.

On that assumption when your are looping through your list of employees you can check your _employee.EmployeeDetailsID value against the session variable and then write the Loop itteration number out to a <script> block that calls the following code.

$("#accordion").accordion( 'activate' , loopIndex);

The documentation for jQuery accordion can be found here as well as details of this method http://docs.jquery.com/UI/Accordion#method-activate

Please note from documentation I have read else where I don't think you should use session variables for this kind of thing.

I would recomend returning the variable as a routing value via the MVC routing system. see the following code as an example.

new { Controller = "Employee", Action = "List", Page = pageNumber, EmployeeId = EmployeeDetailsID }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文