如何在MVC中另一个View内部的View中进行部分工作?

时间:2018-06-21 10:36:52

标签: jquery asp.net-mvc

我在另一个视图Department内有一个视图Company。在视图Department中,有一些基于按钮单击的部分加载。

问题是,现在在按钮上单击Select时,未加载部分。它变得没有反应了。

Department视图正在Company视图内但在部门视图中加载,如果单击Select。它不会打开Partials。

请给我建议一下。

公司型号

public class ClsCompany
    {
        public IEnumerable<ClsDepartment> clsDepartment { get; set; }

    }

控制公司

public ActionResult Company(ClsCompany clscompany)
{
   DepartmentDetails departmentDetails = new DepartmentDetails();      
   clscompany.clsDepartment = departmentDetails.List();
    return View(clsCompany);
}

查看公司

  @model xx.xx.xx.Company.ClsCompany

         <div class="container">
            <div class="panel panel-default">                                           
                    <div class="panel-body">
             @Html.Partial("~/Views/Department/Department.cshtml", Model.clsDepartment)   

                </div>

            </div>

      </div>

管制员部门

  public ActionResult Department()
    {
    DepartmentDetails departmentDetails = new DepartmentDetails();      

       return View(departmentDetails.List());
    }

查看部门

     @model IEnumerable<xx.xx.xx.Department.ClsDepartment>

                    <table>
                        <tr>
                            <th>
                                @Html.DisplayNameFor(m => m.DepartmentName)
                            </th>
                            <th>
                            @Html.DisplayNameFor(m => m.DepartmentType)
                          </th>

                        </tr>

                        @foreach (var item in Model)
                        {
                            <tr>
                                <td>
                              @Html.DisplayFor(modelItem => item.DepartmentName)
                                </td>
                           <th>
                            @Html.DisplayFor(m => m.DepartmentType)
                          </th>
                               <td>
                          <input class="search" type="button" value="Select"
                                       data-assigned="@item.DepartmentId" />
                            </td>

                            </tr>
                        }
                    </table>

 <div id="MyDepartment">

   @using (Html.BeginForm("Department", "Department", FormMethod.Post, new { id = "myform" }))
            {
                <div id="mypartial"> </div>
               <button type="submit" id="submit">Run</button>

            }

        </div>

部分方法

    public ActionResult DepartmentPartialView(string id)
   {

    if (Id == "FNC01")
  {
     return PartialView("~/Views/Department/_Finance.cshtml");
    }

    else if (Id == "ITC02")
    {
     return PartialView("~/Views/Department/_ITC.cshtml");
    }  
 else
    {
     return View();
    }      

}

在按钮单击Select上加载部分的脚本

 $('.search').click(function () {              
                 var id = $(this).data('assigned');
                var route = '@Url.Action("DepartmentPartialView", "Department")?id=' + id ;
                route = encodeURI(route); 
                $('#mypartial').load(route);
}

0 个答案:

没有答案