C# 如何根据ASP.NET MVC和EF中第一个选项卡下的数据在第二个选项卡上显示关联数据

C# 如何根据ASP.NET MVC和EF中第一个选项卡下的数据在第二个选项卡上显示关联数据,c#,asp.net-mvc,linq,entity-framework,C#,Asp.net Mvc,Linq,Entity Framework,我使用的是MVC应用程序和entityframework,我有两个表country和city,这两个表具有PK\U FK关系。在我的UI中,我使用两个选项卡,第一个选项卡用于国家,第二个选项卡用于城市,这两个选项卡都显示在两个局部视图中的网格中。现在我要实现的是,如果我在第一个选项卡中单击某个国家,则相应的国家/城市应显示在第二个选项卡中,而不是完整的国家/城市。如何做到这一点,下面是我已经完成的现有代码 控制器 索引视图 并创建了第一个网格的另一个HTTPPOST操作 [HttpPost]

我使用的是MVC应用程序和entityframework,我有两个表country和city,这两个表具有PK\U FK关系。在我的UI中,我使用两个选项卡,第一个选项卡用于国家,第二个选项卡用于城市,这两个选项卡都显示在两个局部视图中的网格中。现在我要实现的是,如果我在第一个选项卡中单击某个国家,则相应的国家/城市应显示在第二个选项卡中,而不是完整的国家/城市。如何做到这一点,下面是我已经完成的现有代码

控制器

索引视图

并创建了第一个网格的另一个HTTPPOST操作

[HttpPost]
    public ActionResult _gridsecondtab(int id)
    {
        // Find the customer by name
        var countries = db.Countries.FirstOrDefault(c => c.id == id);

        // Get the customers products
        var cities = countries.Citynews;

        // Send products to the View to be rendered
        return PartialView(cities);
    }

但是它没有正常工作,而是复制了第一个网格本身。

您是否同时加载这些选项卡?@pjobs我修改了我的问题,一个选项卡基于html.action执行,其余两个是html.actionlink
<ul>
    <li><a href="#tabs-1">Tab Header 1</a></li>
    <li>@Html.ActionLink("Tab Header 2", "_gridsecondtab")</li>
    <li>>@Html.ActionLink("Tab Header 3", "_gridthirdtab")</li>
</ul>

<div id="tabs-1">
    @Html.Action("_gridfirsttab")
</div>
@if (grid.HasSelection)
{
    conuntry = (firstmvc4.Models.Country)grid.Rows[grid.SelectedIndex].Value;

    @Html.Action("_gridsecondtab", new {id =conuntry.id })

}
[HttpPost]
    public ActionResult _gridsecondtab(int id)
    {
        // Find the customer by name
        var countries = db.Countries.FirstOrDefault(c => c.id == id);

        // Get the customers products
        var cities = countries.Citynews;

        // Send products to the View to be rendered
        return PartialView(cities);
    }