我正在分享我的代码以及我使用 asp dot net core 面临的问题 我有 manager 类、 dto 、 cshtml 和 enum
这是我的 dto 课程
`public class InvestmentDetailDto
{
public InvestmentDetailDto()
{
AmountType = new List<PickList>();
SectionCode = new List<PickList>();
public int Id { get; set; }
public string EmployeeId { get; set; }
public string Name { get; set; }
public string PolicyNumber { get; set; }
public decimal Amount { get; set; }
public decimal AMTAmount { get; set; }
public DateTime InvestmentStartDate { get; set; }
public DateTime InvestmentEndDate { get; set; }
public bool IsDeleted { get; set; }
public List<PickList> AmountType { get; set; }
public List<PickList> SectionCode { get; set; }
public int AmountTypeId { get; set; }
public int SectionCodeId { get; set; }
public string PolicyNo { get; set; }
public bool IsActive { get; set; }
}`
这是我在管理器类中用于映射的循环
foreach (var invest in
investment.EmployeeInvestmentDetails.Where(x =>!x.IsDeleted &&
x.IsActive == true ))
{
var invertDetail = new InvestmentDetailDto();
invertDetail.Name = invest.Name.ToString();
invertDetail.AMTAmount = invest.AMTAmount ?? 0;
invertDetail.Amount = invest.Amount ?? 0;
empSalaryDetail.EmployeeInvestmentDetails.Add(invertDetail);
}
这是cshtml
@foreach (var sectionName in new[] { "80C", "80CCC", "80CCD" })
{
var matchingInvestments = Model.EmployeeInvestmentDetails.Where(x => x.SectionCode.Any(p => p.Value == sectionName)).ToList();
if (matchingInvestments.Any())
{
<tr>
<td class="mainLine" style="padding-left: 2%;">@sectionName</td>
<td class="INRLine"></td>
<td class="INRLine"></td>
<td class="INRLine"></td>
</tr>
foreach (var item in matchingInvestments)
{
<tr>
<td class="mainLine" style="padding-left: 2%;">@item.Name</td>
<td class="INRLine"><b>@item.Amount</b></td>
<td class="INRLine"><b>@item.Amount</b></td>
<td class="INRLine"><b>@item.AMTAmount</b></td>
</tr>
}
}
}
这是创建的枚举
public enum SectionCodeEnum
{
[Display(Name = "80C")]
Eighty_C = 1,
[Display(Name = "80CCC")]
Eighty_CCC = 2,
[Display(Name = "80CCD")]
Eighty_CCD = 3,
部分是一个拾取列表,如下所示
public class PickList
{
public int Id { get; set; }
public string Value { get; set; }
}
每当我在任何应该可见的部分下插入投资名称时(例如80C,其下的投资名称与80CCC和80CCD相同)
相反我什么也没得到
InvestmentDetailDto:这个类看起来是一个DTO(数据传输对象),用于传输投资相关的数据。它包含各种投资细节的属性。您还使用 AmountType 和 SectionCode 的 PickList 列表。
foreach 循环:您使用 foreach 循环迭代投资集合并为每项投资填充 InvestmentDetailDto。循环内的代码根据投资的值设置 InvestmentDetailDto 的属性。
SectionCodeEnum:这是一个枚举,定义了“80C”、“80CCC”和“80CCD”等部分代码。它还使用 [Display] 属性为枚举值提供人类可读的名称。
PickList:这是一个表示具有 ID 和值的项目的类,这是用于在各种上下文中定义选项或项目的常见模式。
如果您对此代码有任何具体疑问、疑虑或问题需要帮助,请提供更多详细信息,我很乐意为您提供进一步帮助。