Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Asp.net局部视图不';行不通_C#_Asp.net_Partial Views - Fatal编程技术网

C# Asp.net局部视图不';行不通

C# Asp.net局部视图不';行不通,c#,asp.net,partial-views,C#,Asp.net,Partial Views,主要观点: @model BTGHRM.Models.EmployeeOverallReport @{ Layout = "~/Views/Shared/_EmployeeMain.cshtml"; } @foreach (var item in Model.ListOfPersonalData) { Html.Partial("Partial/_EmployeeOverallReportList", item); <br/> } @model BTGHR

主要观点:

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

@foreach (var item in Model.ListOfPersonalData)
{
    Html.Partial("Partial/_EmployeeOverallReportList", item);
    <br/>
}
@model BTGHRM.Models.employeeOverall报告
@{
Layout=“~/Views/Shared/_EmployeeMain.cshtml”;
}
@foreach(Model.ListOfPersonalData中的var项)
{
Html.Partial(“Partial/_EmployeeOverallReportList”,项目);

}
我的部分:

@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")
        )
)
}
@model BTGHRM.Models.PersonalData
@{
WebGrid grid=newWebGrid(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(
表样式:“表”,
headerStyle:“table_headerStyle”,
页脚样式:“表格页面样式”,
rowStyle:“table_rowStyle”,
alternatingRowStyle:“table_alternatingRowStyle”,
selectedRowStyle:“表\u selectedRowStyle”,
列:grid.columns(
grid.Column(“ProjectName”,@Resources.Localization.project,格式:@
@item.ProjectName
,样式:“p60”),
grid.Column(“Activity”,@Resources.Localization.Activity,格式:@
@项目.活动
,样式:“p60”),
grid.Column(“ProjectEndDate”,@Resources.Localization.start_date,格式:@
@item.ProjectStartDate
,样式:“p60”),
grid.Column(“ProjectEndDate”,@Resources.Localization.end_date,格式:@
@item.ProjectEndDate
,样式:“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; }
}
公共类员工总体报告
{
//数据块:
公共bool PersonalDataPartBool{get;set;}
personaldata{get;set;}的公共列表列表
//专栏需要:
公共bool EmployeeIdBool{get;set;}
公共bool FirstNameBool{get;set;}
公共bool LastNameBool{get;set;}
公共布尔指定bool{get;set;}
公共bool分区bool{get;set;}
//数据块:
公共bool WorkDataPartBool{get;set;}
public bool ProjectWorkerIdBool{get;set;}
公共bool projectdbool{get;set;}
公共bool ProjectNameBool{get;set;}
公共bool活动bool{get;set;}
公共bool项目startDatebool{get;set;}
公共bool ProjectEndDateBool{get;set;}
}
公共类个人数据
{
//不是全部
公共列表ListOfWorkData{get;set;}
public int EmployeeId{get;set;}
公共字符串名{get;set;}
公共字符串LastName{get;set;}
公共字符串约会{get;set;}
公共字符串除法{get;set;}
//还有更多
}
公共类工作数据
{
public int WorkerId{get;set;}
公共int ProjectId{get;set;}
公共字符串ProjectName{get;set;}
公共字符串活动{get;set;}
[DisplayFormat(DataFormatString=“{0:dd-MMM-yyyy}”)]
公共日期时间?ProjectStartDate{get;set;}
[DisplayFormat(DataFormatString=“{0:dd-MMM-yyyy}”)]
公共日期时间?ProjectEndDate{get;set;}
}
Bool属性用于排序,现在不使用。问题是此代码实际上不返回任何内容:


但是,它返回制动器,并且在跟踪模式下,所有模型都有正确的数据,并且我能够通过断点进入网格。

for循环中的
Html.Partial
仍在为Razor页面调用HtmlHelper。换句话说,您仍然在调用函数,但返回值没有呈现到视图中。你的回路被切断了吗

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

Html.Partial(“Partial/_EmployeeOverallReportList”,项目);

然后,
Html.Partial
将在传递给view\Partial view之前显示为文本

模型的状态是什么?@SimonPrice它是一个模型,包含员工的
列表
,员工列表的每个元素都有自己的
工作数据列表
员工列表
的元素一个接一个地传递到局部视图中,其中使用
工作数据
列表中的数据构建web网格。在跟踪模式下,模型具有有效数据。顺便说一句,我刚刚将代码从partial引入到主视图中,效果很好。@SimonPrice我忘了将@放在Html.partial之前(“partial/_EmployeeOverallReportList”,item);但我不明白为什么这一行不被视为一行文本很高兴我能提供帮助:)@SimonPrice如果你能解释为什么这一行不被视为一行常规文本-回答请允许我标记为解决方案)