Javascript 在模式中显示局部视图,但不提取数据

Javascript 在模式中显示局部视图,但不提取数据,javascript,jquery,asp.net-mvc,model-view-controller,Javascript,Jquery,Asp.net Mvc,Model View Controller,当用户将鼠标悬停在视图中的人名上时,我试图显示一个在局部视图中呈现数据的模式。我可以得到要显示的模式,但是没有数据,而且由于视图中要显示的名称是由linq语句生成的,因此div都具有相同的类名称。这会使页面上的所有名称在将模型悬停在上方时显示模型。我不知道如何克服这些问题 这是我到目前为止所拥有的 JQuery创建并填充模式 $(document).ready(function (data) { $('accountNumber').hover(function () {

当用户将鼠标悬停在视图中的人名上时,我试图显示一个在局部视图中呈现数据的模式。我可以得到要显示的模式,但是没有数据,而且由于视图中要显示的名称是由linq语句生成的,因此div都具有相同的类名称。这会使页面上的所有名称在将模型悬停在上方时显示模型。我不知道如何克服这些问题

这是我到目前为止所拥有的

JQuery创建并填充模式

$(document).ready(function (data) {
    $('accountNumber').hover(function () {
        var id = $(this).data("personID")
        $(".modal").dialog({
            autoOpen: true,
            position: { my: "center", at: "center", of: parent },
            width: 300,
            resizable: false,
            title: 'Accounts Information',
            modal: true,
            open: function () {
                $(this).load('@Url.Action("_AccountNumberModal", "ICMS", ' + id + ')');
            },
            buttons: {
                Ok: function () {
                    $(this).dialog("close");
                }
            }
        });
        return false;
    });
});
局部视图的控制器操作

public ActionResult _AccountNumberModal(SearchViewModel viewModel, string id)
        {
            tblPeople people = db.tblPeoples.FirstOrDefault(x => x.PeopleCounterID.ToString() == id);
            {
                viewModel.FirstName = people.FirstName;
                viewModel.LastName = people.LastName;
                viewModel.AccountNumber = people.AccountNumber;
                viewModel.AccountNumber2 = people.AccountNumber2;
                viewModel.AccountNumber3 = people.AccountNumber3;
                viewModel.AccountNumber4 = people.AccountNumber4;
                viewModel.AccountClosed = people.AccountClosed;
                viewModel.AccountClosed2 = people.AccountClosed2;
                viewModel.AccountClosed3 = people.AccountClosed3;
                viewModel.AccountClosed4 = people.AccountClosed4;
                viewModel.AccountClosedDate1 = people.AccountClosedDate1;
                viewModel.AccountClosedDate2 = people.AccountClosedDate2;
                viewModel.AccountClosedDate3 = people.AccountClosedDate3;
                viewModel.AccountClosedDate4 = people.AccountClosedDate4;
                viewModel.TypeofAccount1 = people.TypeofAccount1;
                viewModel.TypeofAccount2 = people.TypeofAccount2;
                viewModel.TypeofAccount3 = people.TypeofAccount3;
                viewModel.TypeofAccount4 = people.TypeofAccount4;
            }
            return View(viewModel);
        }
@model FHN.EIR.Web.Models.SearchViewModel

<section id="accountNumbers" class="sectionHeadingBold">Account Information</section>
@if (!string.IsNullOrEmpty(Model.AccountNumber))
{
    <dl class="inline dl-rows">
        <dt>
            @Html.DisplayNameFor(model => model.AccountNumber)
        </dt>
        <dd>
            @Html.DisplayFor(model => model.AccountNumber)
        </dd>
        <dt>
            @Html.DisplayNameFor(model => model.TypeofAccount1)
        </dt>
        <dd class="width-275px">
            @Html.DisplayFor(model => model.TypeofAccount1)
        </dd>
        <dt>
            @Html.DisplayNameFor(model => model.AccountClosed)
        </dt>
        <dd class="width-dateField">
            @if (Model.AccountClosed)
                {
                @Html.DisplayName("Closed")
            }
            else
            {
                @Html.DisplayName("Open")
            }
        </dd>
        @if (Model.AccountClosed)
        {
            <dt>
                @Html.DisplayNameFor(model => model.AccountClosedDate1)
            </dt>
                <dd>
                    @Html.DisplayFor(model => model.AccountClosedDate1)
                </dd>
        }
    </dl>
        <br />
    if (!String.IsNullOrEmpty(Model.AccountNumber2))
    {
        <dl class="inline dl-rows">
            <dt>
                @Html.DisplayNameFor(model => model.AccountNumber2)
            </dt>
            <dd>
                @Html.DisplayFor(model => model.AccountNumber2)
            </dd>
            <dt>
                @Html.DisplayNameFor(model => model.TypeofAccount2)
            </dt>
            <dd class="width-250px">
                @Html.DisplayFor(model => model.TypeofAccount2)
            </dd>
            <dt>
                @Html.DisplayNameFor(model => model.AccountClosed2)
            </dt>
            <dd class="width-dateField">
                @if (Model.AccountClosed2)
                    {
                    @Html.DisplayName("Closed")
                }
                else
                {
                    @Html.DisplayName("Open")
                }
            </dd>
            @if (Model.AccountClosed2)
            {
                <dt>
                    @Html.DisplayNameFor(model => model.AccountClosedDate2)
                </dt>
                    <dd>
                        @Html.DisplayFor(model => model.AccountClosedDate2)
                    </dd>
            }
        </dl>
            <br />
    }
    if (!String.IsNullOrEmpty(Model.AccountNumber3))
    {
        <dl class="inline dl-rows">
            <dt>
                @Html.DisplayNameFor(model => model.AccountNumber3)
            </dt>
            <dd>
                @Html.DisplayFor(model => model.AccountNumber3)
            </dd>
            <dt>
                @Html.DisplayNameFor(model => model.TypeofAccount3)
            </dt>
            <dd class="width-250px">
                @Html.DisplayFor(model => model.TypeofAccount3)
            </dd>
            <dt>
                @Html.DisplayNameFor(model => model.AccountClosed3)
            </dt>
            <dd class="width-dateField">
                @if (Model.AccountClosed3)
                    {
                    @Html.DisplayName("Closed")
                }
                else
                {
                    @Html.DisplayName("Open")
                }
            </dd>
            @if (Model.AccountClosed3)
            {
                <dt>
                    @Html.DisplayNameFor(model => model.AccountClosedDate3)
                </dt>
                    <dd>
                        @Html.DisplayFor(model => model.AccountClosedDate3)
                    </dd>
            }
        </dl>
            <br />
    }
    if (!String.IsNullOrEmpty(Model.AccountNumber4))
    {
        <dl class="inline dl-rows">
            <dt>
                @Html.DisplayNameFor(model => model.AccountNumber4)
            </dt>
            <dd>
                @Html.DisplayFor(model => model.AccountNumber4)
            </dd>
            <dt>
                @Html.DisplayNameFor(model => model.TypeofAccount4)
            </dt>
            <dd class="width-250px">
                @Html.DisplayFor(model => model.TypeofAccount4)
            </dd>
            <dt>
                @Html.DisplayNameFor(model => model.AccountClosed4)
            </dt>
            <dd class="width-dateField">
                @if (Model.AccountClosed4)
                    {
                    @Html.DisplayName("Closed")
                }
                else
                {
                    @Html.DisplayName("Open")
                }

            </dd>
            @if (Model.AccountClosed4)
            {
                <dt>
                    @Html.DisplayNameFor(model => model.AccountClosedDate4)
                </dt>
                    <dd>
                        @Html.DisplayFor(model => model.AccountClosedDate4)
                    </dd>
            }
        </dl>
    }
}
else
{
    <dl class="inline dl-rows">
        <dt>
            <span class="mar-l-15px inline-messages">There are no accounts associated with this person</span>
        </dt>
    </dl>
}
局部视图

public ActionResult _AccountNumberModal(SearchViewModel viewModel, string id)
        {
            tblPeople people = db.tblPeoples.FirstOrDefault(x => x.PeopleCounterID.ToString() == id);
            {
                viewModel.FirstName = people.FirstName;
                viewModel.LastName = people.LastName;
                viewModel.AccountNumber = people.AccountNumber;
                viewModel.AccountNumber2 = people.AccountNumber2;
                viewModel.AccountNumber3 = people.AccountNumber3;
                viewModel.AccountNumber4 = people.AccountNumber4;
                viewModel.AccountClosed = people.AccountClosed;
                viewModel.AccountClosed2 = people.AccountClosed2;
                viewModel.AccountClosed3 = people.AccountClosed3;
                viewModel.AccountClosed4 = people.AccountClosed4;
                viewModel.AccountClosedDate1 = people.AccountClosedDate1;
                viewModel.AccountClosedDate2 = people.AccountClosedDate2;
                viewModel.AccountClosedDate3 = people.AccountClosedDate3;
                viewModel.AccountClosedDate4 = people.AccountClosedDate4;
                viewModel.TypeofAccount1 = people.TypeofAccount1;
                viewModel.TypeofAccount2 = people.TypeofAccount2;
                viewModel.TypeofAccount3 = people.TypeofAccount3;
                viewModel.TypeofAccount4 = people.TypeofAccount4;
            }
            return View(viewModel);
        }
@model FHN.EIR.Web.Models.SearchViewModel

<section id="accountNumbers" class="sectionHeadingBold">Account Information</section>
@if (!string.IsNullOrEmpty(Model.AccountNumber))
{
    <dl class="inline dl-rows">
        <dt>
            @Html.DisplayNameFor(model => model.AccountNumber)
        </dt>
        <dd>
            @Html.DisplayFor(model => model.AccountNumber)
        </dd>
        <dt>
            @Html.DisplayNameFor(model => model.TypeofAccount1)
        </dt>
        <dd class="width-275px">
            @Html.DisplayFor(model => model.TypeofAccount1)
        </dd>
        <dt>
            @Html.DisplayNameFor(model => model.AccountClosed)
        </dt>
        <dd class="width-dateField">
            @if (Model.AccountClosed)
                {
                @Html.DisplayName("Closed")
            }
            else
            {
                @Html.DisplayName("Open")
            }
        </dd>
        @if (Model.AccountClosed)
        {
            <dt>
                @Html.DisplayNameFor(model => model.AccountClosedDate1)
            </dt>
                <dd>
                    @Html.DisplayFor(model => model.AccountClosedDate1)
                </dd>
        }
    </dl>
        <br />
    if (!String.IsNullOrEmpty(Model.AccountNumber2))
    {
        <dl class="inline dl-rows">
            <dt>
                @Html.DisplayNameFor(model => model.AccountNumber2)
            </dt>
            <dd>
                @Html.DisplayFor(model => model.AccountNumber2)
            </dd>
            <dt>
                @Html.DisplayNameFor(model => model.TypeofAccount2)
            </dt>
            <dd class="width-250px">
                @Html.DisplayFor(model => model.TypeofAccount2)
            </dd>
            <dt>
                @Html.DisplayNameFor(model => model.AccountClosed2)
            </dt>
            <dd class="width-dateField">
                @if (Model.AccountClosed2)
                    {
                    @Html.DisplayName("Closed")
                }
                else
                {
                    @Html.DisplayName("Open")
                }
            </dd>
            @if (Model.AccountClosed2)
            {
                <dt>
                    @Html.DisplayNameFor(model => model.AccountClosedDate2)
                </dt>
                    <dd>
                        @Html.DisplayFor(model => model.AccountClosedDate2)
                    </dd>
            }
        </dl>
            <br />
    }
    if (!String.IsNullOrEmpty(Model.AccountNumber3))
    {
        <dl class="inline dl-rows">
            <dt>
                @Html.DisplayNameFor(model => model.AccountNumber3)
            </dt>
            <dd>
                @Html.DisplayFor(model => model.AccountNumber3)
            </dd>
            <dt>
                @Html.DisplayNameFor(model => model.TypeofAccount3)
            </dt>
            <dd class="width-250px">
                @Html.DisplayFor(model => model.TypeofAccount3)
            </dd>
            <dt>
                @Html.DisplayNameFor(model => model.AccountClosed3)
            </dt>
            <dd class="width-dateField">
                @if (Model.AccountClosed3)
                    {
                    @Html.DisplayName("Closed")
                }
                else
                {
                    @Html.DisplayName("Open")
                }
            </dd>
            @if (Model.AccountClosed3)
            {
                <dt>
                    @Html.DisplayNameFor(model => model.AccountClosedDate3)
                </dt>
                    <dd>
                        @Html.DisplayFor(model => model.AccountClosedDate3)
                    </dd>
            }
        </dl>
            <br />
    }
    if (!String.IsNullOrEmpty(Model.AccountNumber4))
    {
        <dl class="inline dl-rows">
            <dt>
                @Html.DisplayNameFor(model => model.AccountNumber4)
            </dt>
            <dd>
                @Html.DisplayFor(model => model.AccountNumber4)
            </dd>
            <dt>
                @Html.DisplayNameFor(model => model.TypeofAccount4)
            </dt>
            <dd class="width-250px">
                @Html.DisplayFor(model => model.TypeofAccount4)
            </dd>
            <dt>
                @Html.DisplayNameFor(model => model.AccountClosed4)
            </dt>
            <dd class="width-dateField">
                @if (Model.AccountClosed4)
                    {
                    @Html.DisplayName("Closed")
                }
                else
                {
                    @Html.DisplayName("Open")
                }

            </dd>
            @if (Model.AccountClosed4)
            {
                <dt>
                    @Html.DisplayNameFor(model => model.AccountClosedDate4)
                </dt>
                    <dd>
                        @Html.DisplayFor(model => model.AccountClosedDate4)
                    </dd>
            }
        </dl>
    }
}
else
{
    <dl class="inline dl-rows">
        <dt>
            <span class="mar-l-15px inline-messages">There are no accounts associated with this person</span>
        </dt>
    </dl>
}
@model FHN.EIR.Web.Models.SearchViewModel
帐户信息
@如果(!string.IsNullOrEmpty(Model.AccountNumber))
{
@Html.DisplayNameFor(model=>model.AccountNumber)
@DisplayFor(model=>model.AccountNumber)
@DisplayNameFor(model=>model.TypeofAccount1)
@DisplayFor(model=>model.TypeofAccount1)
@DisplayNameFor(model=>model.AccountClosed)
@如果(型号:AccountClosed)
{
@Html.DisplayName(“已关闭”)
}
其他的
{
@Html.DisplayName(“打开”)
}
@如果(型号:AccountClosed)
{
@DisplayNameFor(model=>model.AccountClosedDate1)
@DisplayFor(model=>model.AccountClosedDate1)
}

如果(!String.IsNullOrEmpty(Model.AccountNumber2)) { @DisplayNameFor(model=>model.AccountNumber2) @DisplayFor(model=>model.AccountNumber2) @DisplayNameFor(model=>model.TypeofAccount2) @DisplayFor(model=>model.TypeofAccount2) @DisplayNameFor(model=>model.AccountClosed2) @if(型号AccountClosed2) { @Html.DisplayName(“已关闭”) } 其他的 { @Html.DisplayName(“打开”) } @if(型号AccountClosed2) { @DisplayNameFor(model=>model.AccountClosedDate2) @DisplayFor(model=>model.AccountClosedDate2) }
} 如果(!String.IsNullOrEmpty(Model.AccountNumber3)) { @DisplayNameFor(model=>model.AccountNumber3) @DisplayFor(model=>model.AccountNumber3) @DisplayNameFor(model=>model.TypeofAccount3) @DisplayFor(model=>model.TypeofAccount3) @DisplayNameFor(model=>model.AccountClosed3) @if(型号AccountClosed3) { @Html.DisplayName(“已关闭”) } 其他的 { @Html.DisplayName(“打开”) } @if(型号AccountClosed3) { @DisplayNameFor(model=>model.AccountClosedDate3) @DisplayFor(model=>model.AccountClosedDate3) }
} 如果(!String.IsNullOrEmpty(Model.AccountNumber4)) { @DisplayNameFor(model=>model.AccountNumber4) @DisplayFor(model=>model.AccountNumber4) @DisplayNameFor(model=>model.TypeofAccount4) @DisplayFor(model=>model.TypeofAccount4) @DisplayNameFor(model=>model.AccountClosed4) @if(型号AccountClosed4) { @Html.DisplayName(“已关闭”) } 其他的 { @Html.DisplayName(“打开”) } @if(型号AccountClosed4) { @DisplayNameFor(model=>model.AccountClosedDate4) @DisplayFor(model=>model.AccountClosedDate4) } } } 其他的 { 没有与此人关联的帐户 }
更新


我能够得到数据来填充。只是不知道如何使它只让悬停在上面的名称打开相关模态,而不是让所有名称打开模态?

局部视图不使用操作加载。必须直接向它们传递一个模型

@Html.Partial("_MyPartial", myPartialModel)
如果不传递模型,则会隐式传递主视图模型

如果需要使用动作渲染局部视图,那么您将讨论子动作。其语法是:

@Html.Action("ActionName", "ControllerName")
然而,有几件事需要注意。用于此操作的操作应返回
PartialView
,而不是
View
。局部视图用作局部视图时仅为局部视图。如果返回
视图
,则局部视图的行为将与标准视图相同,并使用布局。接下来,自从你的行动