【发布时间】:2015-07-28 20:23:50
【问题描述】:
我的控制器方法中有以下代码向成员类型的列表视图提供数据:
[HttpGet]
public ActionResult SelectMembershipType(int clubId)
{
//Populate the list
var membershipTypes = from s in db.MembershipTypes
where (s.ClubId == clubId && s.Dormant == false)
orderby s.Type
select s;
//Generate the ViewModel with the appropriate membership types
var viewModel = membershipTypes.Select(t => new SelectMembershipTypeViewModel
{
//Select appropriate Cost based on current month
if(DateTime.Now.Month == t.ReducedMonth)
{
Cost = t.ReducedCost;
}
else
{
Cost = t.Cost;
}
ClubId = club.ClubId,
Name = club.Name,
MembershipName = t.Type,
MembershipType = t.MembershipTypeClassification.Type,
MembershipTypeId = t.MembershipTypeId,
});
return View(viewModel);
}
我放入的 if 语句不起作用,它会引发几个错误。 我正在尝试将 if 语句应用于 Cost 的值,即如果今天的月份等于数据库中每个会员类型的 ReducedMonth,则使 Cost 的值等于 Membership Types ReducedCost 值,如果不等于其取而代之的是成本。 每个 MembershipType 可以有不同的减少月份和费用
我不确定正确的语法来正确编码
【问题讨论】:
-
确切的错误信息是什么?
标签: c# asp.net-mvc