【发布时间】:2012-07-17 01:51:08
【问题描述】:
我有一个@heper pagination 函数。那就是有两个 View helper ViewBag 和 Url。
这个分页将被很多页面使用,所以我将代码从Views 文件夹转移
到App_Code 文件夹。 App_Code/Helper.cshtml里面的代码
@helper buildLinks(int start, int end, string innerContent)
{
for (int i = start; i <= end; i++)
{
<a class="@(i == ViewBag.CurrentPage ? "current" : "")" href="@Url.Action("index", "country", new { page = i })">@(innerContent ?? i.ToString())</a>
}
}
但是现在当我运行应用程序时。它抛出错误
error CS0103:The name 'ViewBag' does not exist in the current context
error CS0103:The name 'Url' does not exist in the current context
我是否需要导入任何命名空间或问题出在哪里?
我想做的方式是完美的吗?
【问题讨论】:
标签: asp.net-mvc-3 razor