问题
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;
}
回答1:
You should put it into the App_Code folder. There is an awesome article for you to read ASP.NET MVC Helpers
来源:https://stackoverflow.com/questions/12265512/where-should-i-locate-shared-helper-functions-in-mvc-razor