2014-10-11 72 views
0

在Asp.net MVC 4中,我想制作一个html扩展方法。MVC Razor 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一个延伸,它可以接收<脚本标记>?

回答

0

您可以使用扩展:

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

@Html.Test("my test")