我的模型有一个object
属性和一个值类型ID号,我想根据值类型号创建不同的编辑器控件。
我尝试使用@help
Razor构造,但是助手中的内容都没有呈现在页面上。
@helper noEditor()
{
<div>noEditor</div>
}
@helper stringEditor()
{
<div>stringEditor</div>
}
@helper intEditor()
{
<div>intEditor</div>
}
@helper boolEditor()
{
<div>boolEditor</div>
}
@helper collectionEditor()
{
<div>collectionEditor</div>
}
@switch(Model.ValueTypeId)
{
case 1: stringEditor(); break;
case 2: intEditor(); break;
case 3: boolEditor(); break;
case 4: collectionEditor(); break;
default: noEditor(); break;
}
当我在@switch
上设置断点时,我可以看到调试器移动到正确的帮助程序,但它会立即跳过函数结尾并退出switch,没有任何内容被渲染。你有什么想法我做错了什么吗?
@if(Model.Any()) { @Html.EditorFor(...); }
- Miguel