Razor代码注释
本文关键字:注释 代码 Razor | 更新日期: 2023-09-27 18:04:49
我试图在我的剃刀视图内重写非常长复杂的if语句和switch语句。因此,注释肯定有助于提高可读性。问题是
@if(IsManager(){
switch(Model.ReportType){
case ReportType.NewReport:
if (case1){
// bla bla bla
//
}
else if (case2){
// bla blab bla
//
}
break;
case ReportType.FooReport:
if (fooBar){
....
无论如何,这里有一个非常简单的例子,它会出现在剃刀代码块中。现在,如果我想在那里添加简单的注释来帮助提高可读性,那就全坏了!!交货。
@if(IsManager(){ @* TALENT MANAGER *@
switch(Model.ReportType){
case ReportType.NewReport:
让智能感知变得非常疯狂,我尝试了这种风格的注释
@if(IsManager(){ // TALENT MANAGER
switch(Model.ReportType){
case ReportType.NewReport:
没有运气,我做错了什么吗?
您可以将可重用的(或复杂的)视图代码分组到一个帮助器中。helper可以在自己的文件或视图中定义。
@helper DoSomethingWhenManager(bool isManager, ReportModel model)
{
if(isManager)
{
switch(model.ReportType) // This is a comment about the report
{
// ...
}
{
}
视图:
<div>
@DoSomethingWhenManager(IsManager(), Model)
</div>
这个对我来说很好
@if (1 < 9) { //Hello
<b>Hey, there!</b>
}
我使用Visual Studio 2013 Express for Web