我应该在哪里找到MVC剃刀共享@helper功能 [英] Where should I locate shared @helper functions in MVC Razor
本文介绍了我应该在哪里找到MVC剃刀共享@helper功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个辅助函数,轮流分钟打入小时/分钟。我现在有它在我的layout.cshtml但每个页面看不到的功能。我应该在哪里放置辅助函数,这样的每个页面可以看到它?
@helper DisplayElapsedTime(INT timeInMins){
串TIMESTR =;
如果(timeInMins> = 60){
INT小时= timeInMins / 60;
timeInMins - =小时* 60;
TIMESTR =小时+H;
}
如果(timeInMins大于0){
TIMESTR + = timeInMins +M;
}
@timeStr;
}
解决方案
您应该把它放到 APP_ code 文件夹中。有供您阅读<一个一个真棒文章href=\"http://weblogs.asp.net/scottgu/archive/2011/05/12/asp-net-mvc-3-and-the-helper-syntax-within-razor.aspx\">ASP.NET MVC助手
I have a helper function that turns minutes into hours/mins. I currently have it in my layout.cshtml but each page cannot see the function. Where should I put the helper function such that every page can see it?
@helper DisplayElapsedTime(int timeInMins){
String timeStr = "";
if (timeInMins >= 60) {
int hours = timeInMins/60;
timeInMins -= hours * 60;
timeStr = hours + "h ";
}
if (timeInMins > 0){
timeStr += timeInMins + "m";
}
@timeStr;
}
解决方案
You should put it into the App_Code folder. There is an awesome article for you to read ASP.NET MVC Helpers
这篇关于我应该在哪里找到MVC剃刀共享@helper功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文