【问题标题】:MVC Razor Html helperMVC Razor Html 助手
【发布时间】:2014-10-11 07:50:06
【问题描述】:

在 Asp.net MVC 4 中,我想做一个 html 扩展方法。

我希望它像这样工作:

在 Razor 视图中:

<button type='button' click='domethod'>click</button>
 @helper.minify(
    <script>
        function domethod() {
             alert('I'm script!');
        }
    </script>
 );

我想我怎样才能让它渲染:

<button type='button' click='domethod'>click</button>
<script>function domethod() {alert('I'm script!');}</script>

我可以在 backcode 中创建一个扩展,它可以接收

【问题讨论】:

    标签: asp.net-mvc razor model-view-controller


    【解决方案1】:

    你可以使用扩展:

    public static class Extensions
    {
        public static MvcHtmlString Test(this HtmlHelper html, string expression)
        {
            return new MvcHtmlString("Data");
        }
    }
    
    @Html.Test("my test")
    

    【讨论】:

      猜你喜欢
      • 2013-07-12
      • 2011-05-25
      • 2012-09-13
      • 1970-01-01
      • 2011-08-04
      • 1970-01-01
      • 1970-01-01
      • 2012-08-30
      • 2019-09-04
      相关资源
      最近更新 更多