我已经阅读了几篇类似的帖子,但他们没有解决我的问题。这是可以正常工作的代码。
<ul>
@foreach (var row in db.Query(readSchedule,dt,pd2))
{
sid = @row.ScheduleId;
pd = @row.Date.ToString();
cn = @row.CourseName;
cut = @row.Cutoff;
cost = @row.Cost;
fa = @row.Fadd;
var dow=@row.Date.DayOfWeek;
pp=@row.PrePay;
<li><a href="/MyFiles/Signup1.cshtml? &sid=@sid&pd=@pd&cn=@cn&cut=@cut&cost=@cost&fa=@fa&pp=@pp">
@cn on @pd (@dow)</a></li>
}
</ul>
当我添加下面显示的if语句时,我收到语法错误消息;预期
<ul>
@foreach (var row in db.Query(readSchedule,dt,pd2))
{
sid = @row.ScheduleId;
pd = @row.Date.ToString();
cn = @row.CourseName;
cut = @row.Cutoff;
cost = @row.Cost;
fa = @row.Fadd;
var dow=@row.Date.DayOfWeek;
pp=@row.PrePay;
if (pp=="")
{pp="none";}
<li><a href="/MyFiles/Signup1.cshtml? &sid=@sid&pd=@pd&cn=@cn&cut=@cut&cost=@cost&fa=@fa&pp=@pp">
@cn on @pd (@dow)</a></li>
}
答案 0 :(得分:0)
我不认为剃刀编译器是完美的,特别是当被要求在html和C#之间来回切换时。话虽如此,我可能会以不需要切换的方式编写该行:
pp = @( (@row.PrePay == "" ? "none" : row.PrePay )