2016-03-07 52 views
1

如何将模型作为参数传递给自定义的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") 
+0

它不可能在'@ helper'中使用表达式(至少具有泛型类型参数)。改为使用'HtmlHelper'扩展方法。 –

回答

0

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

+1

我可以,但我看到是否有办法用自定义剃须刀帮手来做到这一点。 – Jack