[英]Mixing razor code with HTML
Hi my mark up has snippets like below 嗨,我的标记有如下所示的片段
<thead>
<tr class="">
<th data-field="firstname">First Name</th>
@{
foreach (MapDetail geMapDetailHead in Model.mapDetails)
{
string firstText, secText, thirdText;
if (geMapDetailHead.ResultTypeIDs.Equals("-9999"))
{
foreach (string rt in geMapDetailHead.ResultTypeIDs.Split(','))
{
firstText = @geMapDetailHead.Name;
string tab = geMapDetailHead.year;
int? month = geMapDetailHead.Month != 0 ? geMapDetailHead.Month : (geMapDetailHead.mapheader.Month != 0 ? geMapDetailHead.mapheader.Month : 0);
//switch (month.GetValueOrDefault())
//{
// default:
// tab += "";
// break;
// case 1:
// tab += " Jan";
// break;
// case 2:
// tab += " Feb";
// break;
// case 3:
// tab += " Mar";
// break;
// case 4:
// tab += " Apr";
// break;
// case 5:
// tab += " May";
// break;
// case 6:
// tab += " Jun";
// break;
// case 7:
// tab += " Jul";
// break;
// case 8:
// tab += " Aug";
// break;
// case 9:
// tab += " Sep";
// break;
// case 10:
// tab += " Oct";
// break;
// case 11:
// tab += " Nov";
// break;
// case 12:
// tab += " Dec";
// break;
//}
//secText = tab;
<th id=@geMapDetailHead.MapDetailID>@firstText @secText</th>
} @*end for loop*@
}
} @*end for loop*@
}
</tr>
</thead>
As soon as i un comment the switch statement it stops recognizing tag as markup. 只要我对switch语句发表评论,它就会停止将标记识别为标记。 i have also tried putting
我也尝试过
@:<th id=@geMapDetailHead.MapDetailID>@firstText @secText</th>
but did not work. 但没有奏效。 How can i mix both the code and markup?
我如何混合代码和标记?
Well turned out that i had applied 1 extra @ in the following line 事实证明,我在下一行中应用了1个额外的@
firstText = @geMapDetailHead.Name;
I changed it to 我改成了
firstText = geMapDetailHead.Name;
and BINGO!! 和BINGO !! Cheers
干杯
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.