简体   繁体   English

Asp.net 部分视图不起作用

[英]Asp.net partial view doesn't work

Main view:主要观点:

@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")
        )
)
}

My models:我的模型:

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 properties are made for sorting purposes and they are not in use now. Bool 属性用于排序目的,现在不使用。 The problem is that this code returns literally nothing:问题是这段代码实际上什么都不返回:

在此处输入图片说明

However it returns brakes and in tracing mode all models have correct data and i am able to get inside the grid with breakpoints.然而,它返回刹车,在跟踪模式下所有模型都有正确的数据,我能够通过断点进入网格。

The Html.Partial in your for loop is still calling the HtmlHelper for the Razor Page. for 循环中的Html.Partial仍在为 Razor 页面调用 HtmlHelper。 In other words, you were still calling the function, but that return value wasn't being rendered into the view.换句话说,您仍在调用该函数,但该返回值并未呈现到视图中。 Had your loop been如果你的循环是

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

Then the Html.Partial would have shown as text然后Html.Partial将显示为文本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM