从剃刀ASP.Net MVC3另一个视图使用@helpers [英] Using @helpers from another View in Razor ASP.Net MVC3

查看:120
本文介绍了从剃刀ASP.Net MVC3另一个视图使用@helpers的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要写一些简单的 @helpers 若干意见的使用。
我想他们是剃刀.cshtml文件(不是在C#类)里面有HTML语法高亮显示。

I want to write a few simple @helpers to use in several views. I want them to be inside a Razor .cshtml file (not in a c# class) to have the HTML syntax highlighted.

我可以轻松地访问 @helpers 同一视图中写的,我可以把它们分成 Helpers.cshtml ,如果我把这个 Helpers.cshtml 成APP_ code文件夹,我可以从通过任何View @ Helpers.MyHelper访问它()。但我希望他们只有几页是可访问的。

I can easily access @helpers written within the same View, I can separate them into Helpers.cshtml, and if I put this Helpers.cshtml into an App_Code folder I can access it from any View via @Helpers.MyHelper(). But I want them to be accessible only for a few pages.

我认为,它可以像把一个@using如果佣工在C#类,但什么是只是另一种看法命名空间?..

I think, it could be like putting a @using if the helpers are in c# class, but what is the namespace for just another view?..

推荐答案

抱歉,但这是不可能的存储在 APP_ code 文件夹助理为 .cshtml 文件。他们将所有视图之间共享。

Sorry, but that's not possible with helpers stored in the App_Code folder as .cshtml files. They will be shared among all views.

这篇关于从剃刀ASP.Net MVC3另一个视图使用@helpers的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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