代码之家  ›  专栏  ›  技术社区  ›  gene

MVC:在弹出窗口中显示部分视图的数据时,主视图中也会显示相同的数据,其中定义了Ajax.ActionLink

  •  0
  • gene  · 技术社区  · 6 年前

    我有MVC视图,视图1。

    这个视图有一个按钮 Ajax.ActionLink 逻辑。 Partial View 加载到弹出窗口中。我该怎么做?

    目前,数据是显示的,但是它显示在主视图(View1)中,就在我定义的地方

    这是我在View1中的代码,我在View1中执行Ajax调用以显示 PartialView :

    Alax.ActionLink("Click here", "ShowPartialView","MyController", new AjaxOptions{....}, new class{....})  
    

    我的控制器具有以下逻辑,将显示 局部视图 :

    public PartialViewResult ShowPartialView()
    {
          return("_MyPartialView");
    }
    

    public MyEntity ObjectEntity {get;set}
    

    我的 局部视图

    <div>
      <table>
        <thead>
          <tr>
           <th></th>
           <th></th>
          </tr>
       </thead>
          <tbody>
            <tr>
              <td></td>
              <td></td>
           </tr>
            <tr>
              <td></td>
              <td></td>
           </tr>
        </tbody>
     </table>
    </div>
    

    以及获取数据的逻辑 Json :

    <script>
    $.getJSON("MyController/GetData", function(result){
              ....Build the table from result
    });
    </script>
    

    然后在控制器中定义一个方法:

    public JasonResult GetData()
    {
           return Json(MyModel.ObjectEntitity.ListOfObjects);
    }
    

    目前,数据显示在弹出窗口中,但是,它也显示在主视图(View1)中,正是我使用Ajax.ActionLink()的地方

    0 回复  |  直到 6 年前