2016-09-23 60 views
-1

主要观点:Asp.net局部视图不起作用

@model BTGHRM.Models.EmployeeOverallReport 
@{ 
    Layout = "~/Views/Shared/_EmployeeMain.cshtml"; 
} 

@foreach (var item in Model.ListOfPersonalData) 
{ 
    Html.Partial("Partial/_EmployeeOverallReportList", item); 
    <br/> 
} 

MyPartial:

@model BTGHRM.Models.PersonalData 
@{ 
WebGrid grid = new WebGrid(Model.ListOfWorkData, canSort: false, rowsPerPage: 15); 
} 

@Html.Label(Model.FirstName) 
@Html.Label(Model.LastName) 
@Html.Label(Model.Appointment) 
@Html.Label(Model.Division) 

@if (Model.ListOfWorkData.Any()) 
{ 
@grid.GetHtml(
     tableStyle: "table", 
     headerStyle: "table_HeaderStyle", 
     footerStyle: "table_PagerStyle", 
     rowStyle: "table_RowStyle", 
     alternatingRowStyle: "table_AlternatingRowStyle", 
     selectedRowStyle: "table_SelectedRowStyle", 
     columns: grid.Columns(
      grid.Column("ProjectName", @Resources.Localization.project, format: @<text> 
       <span class="display-mode"><label id="ProjectNameLabel">@item.ProjectName</label></span> 
      </text>, style: "p60"), 
      grid.Column("Activity", @Resources.Localization.activity, format: @<text> 
       <span class="display-mode"><label id="ActivityLabel">@item.Activity</label></span> 
      </text>, style: "p60"), 
      grid.Column("ProjectEndDate", @Resources.Localization.start_date, format: @<text> 
       <span class="display-mode"><label id="ProjectStartDate">@item.ProjectStartDate</label></span> 
      </text>, style: "p60"), 
      grid.Column("ProjectEndDate", @Resources.Localization.end_date, format: @<text> 
       <span class="display-mode"><label id="ProjectEndDate">@item.ProjectEndDate</label></span> 
      </text>, style: "p60") 
     ) 
) 
} 

我的模型:

public class EmployeeOverallReport 
{ 
    //DataBlock: 
    public bool PersonalDataPartBool { get; set; } 
    public List<PersonalData> ListOfPersonalData { get; set; } 
    //ColumnsNeeded: 
    public bool EmployeeIdBool { get; set; } 
    public bool FirstNameBool { get; set; } 
    public bool LastNameBool { get; set; } 
    public bool AppointmentBool { get; set; } 
    public bool DivisionBool { get; set; } 

    //DataBlock: 
    public bool WorkDataPartBool { get; set; } 
    public bool ProjectWorkerIdBool { get; set; } 
    public bool ProjectIdBool { get; set; } 
    public bool ProjectNameBool { get; set; } 
    public bool ActivityBool { get; set; } 
    public bool ProjectStartDateBool { get; set; } 
    public bool ProjectEndDateBool { get; set; } 

} 

public class PersonalData 
{ 
    //Not all 
    public List<WorkData> ListOfWorkData { get; set; } 
    public int EmployeeId { get; set; } 
    public string FirstName { get; set; } 
    public string LastName { get; set; } 
    public string Appointment { get; set; } 
    public string Division { get; set; } 
    //And more 
} 

public class WorkData 
{ 
    public int WorkerId { get; set; } 
    public int ProjectId { get; set; } 
    public string ProjectName { get; set; } 
    public string Activity { get; set; } 
    [DisplayFormat(DataFormatString = "{0:dd MMM yyyy}")] 
    public DateTime? ProjectStartDate { get; set; } 
    [DisplayFormat(DataFormatString = "{0:dd MMM yyyy}")] 
    public DateTime? ProjectEndDate { get; set; } 
} 

布尔属性进行排序的目的,他们做了现在没有被使用。问题是,这种代码返回几乎一无所有:

enter image description here

但是它返回制动和跟踪模式下,所有型号都有正确的数据,我能够获得断点的网格内。

+0

它传递给视图\局部视图是什么型号的状态之前? –

+0

@SimonPrice这是一个模型,它包含一个“员工列表”,员工列表的每个元素都有自己的“工作数据”列表。 “员工列表”的元素将逐个传递到局部视图中,其中,网格是使用“工作数据”列表中的数据构建的。在跟踪模式中有有效的数据。 顺便说一句,我只是从部分代码进入主视图,它工作正常。 –

+0

@SimonPrice我忘了把@放在Html.Partial之前(“Partial/_EmployeeOverallReportList”,item); 但我不明白为什么这行并没有被看作是一行文字 –

回答

1

for循环中的Html.Partial仍在调用HtmlHelper作为Razor页面。换句话说,你还在调用这个函数,但是那个返回值没有被渲染到视图中。有你的循环一直

<text> 
    Html.Partial("Partial/_EmployeeOverallReportList", item); 
</text> 

然后Html.Partial会显示为文本

相关问题