Razor 声明性帮助程序将模型作为参数传递


如何将

模型作为参数传递给自定义 html 帮助程序?

目前我有以下文件

@helper LabelFor(string label, string hint)
{
    <label for="@label">@label</label>
    <span class="mif-info"
          data-role="hint"
          data-hint-background="bg-blue"
          data-hint-color="fg-white"
          data-hint-mode="1"
          data-hint-position="top"
          data-hint="@hint"></span>
}

哪个被称为

@MyHelpers.LabelFor(Html.DisplayNameFor(model => model.Title).ToString(), "Description")

我怎样才能将其简化为

@MyHelpers.LabelFor(model => model.Title, "Description")

我想,你可以使用MVC DisplayTemplates实现同样的效果。你试过这条路吗?

最新更新