ASP.NET MVC / Jquery Accordion - 如何在Jquery Accordion上执行以下ajax请求?

问题描述:

我已经使用Asp.net mvc创建了一个Jquery Accordion,它运行正常。手风琴显示员工姓名列表,当我点击某个项目时,它会显示详细信息。我想发送ajax请求,以便在他们点击某个项目时获取员工详细信息,而不是立即加载所有员工详细信息。请看下面的代码。



另外,请告诉我如何保持手风琴中的第一项折叠而不是显示细节,是否有任何方法可以不使用& nbsp向右移动标题?



我将非常感谢任何帮助 - 谢谢。

Hi, I''ve created a Jquery Accordion using Asp.net mvc, and it''s working fine. The accordion displays a list of employee names, and when i click on an item, it shows the details. I''d like to send an ajax request to get the employee details when they click on an item, instead of loading all the employee details at once. Please look at my code below.

Also, please tell me how to keep the first item in the accordion collapsed instead of showing the details, and is there any way to move the heading a bit to the right without using &nbsp ?

I would greatly appreciate any help - thanks.

<div id="accordion">
    @foreach (var item in Model.Employees)
    {
        <h3>&nbsp;&nbsp;&nbsp;&nbsp;@item.EmployeeName</h3>
        <div id = "accordiondiv">
            <p>Address: @item.Address</p>
            <p>Town: @item.Town</p>
            <p>Postcode: @item.PostCode</p>
            <p>PhoneNumber: @item.PhoneNumber</p>
        </div>
    }
</div>

<script>
$(function () {
    $("Accordion").click(function (evt) {
                $.ajax({
                url: "/Accordion/GetEmployeeDetails",
                type: 'POST',
                data:
             //need code to pass the employeeid that was clicked on the accordion,
                success: function (data) {
                    $.each(data, function (i, val) {
            //need code to populate the respective accordion with the employee details
                    });
                }
            });
        }
    });
</script>

(function(){
(function () {


(Accordion ).click(function(evt){
("Accordion").click(function (evt) {


.ajax({
url:/ Accordion / GetEmployeeDetails,
type:'POST',
数据:
//需要代码来传递在手风琴上点击的employeeid,
成功:函数(数据){
.ajax({ url: "/Accordion/GetEmployeeDetails", type: 'POST', data: //need code to pass the employeeid that was clicked on the accordion, success: function (data) {