Where should I locate shared @helper functions in

2019-03-12 02:19发布

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条回答
疯言疯语
2楼-- · 2019-03-12 03:16

You should put it into the App_Code folder. There is an awesome article for you to read ASP.NET MVC Helpers

查看更多
登录 后发表回答