ASP.NET MVC 4自定义HTML助手文件夹位置 [英] ASP.NET MVC 4 custom HTML Helpers folder location

查看:119
本文介绍了ASP.NET MVC 4自定义HTML助手文件夹位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始开发使用剃刀语法ASP.NET MVC框架4的应用程序。我想知道在哪里(文件夹位置)我要创造我的HTML Helper类。最佳实践。

I'm starting to develop an application using ASP.NET MVC 4 framework with Razor syntax. I want to know where (folder location) I should create my HTML Helper class. Best practice.

例如:


  • VisualStudioSolution

    • Controlles

    • HTML

      • HtmlHelperClass.vb

      推荐答案

      使用<一个href=\"http://stackoverflow.com/questions/3981175/where-should-i-place-declarative-html-helpers-in-asp-net-mvc-3\">this.To使用@helper功能剃刀您需要将CSHTML文件放置在您的应用程序的APP_ code文件夹中。有一个在ASP.NET MVC 3 ScottGu的博客文章没有查看/助手的文件夹被写入之前的功能已全面实施,而一些票据也有不完全准确了。

      use this.To use the "@helper" feature in Razor you need to place the CSHTML file in the App_Code folder of your app. There is no "Views/Helpers" folder in ASP.NET MVC 3. ScottGu's blog post was written before the feature was fully implemented, and some of the notes there are not entirely accurate anymore.

      要调用@helper你写,你必须包括文件名,以及它里面的助手的名字。例如,如果你有这样的帮手:

      To call the "@helper" that you wrote you have to include both the filename as well as the name of the helper inside it. For example, if you have this helper:

      ~/App_Code/MyHelper.cshtml
      

      和此内容:

      @helper ShowStuff(string stuff) {
          <p>@stuff</p>
      }
      

      然后调用它像这样:

      Then you call it like so:

      @MyHelper.ShowStuff("some stuff!")
      

      这篇关于ASP.NET MVC 4自定义HTML助手文件夹位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆