我有一個@heper pagination
函數。這是有兩個查看幫手ViewBag
和Url
。 這個分頁會被這麼多頁面使用,所以我將Views
文件夾 的代碼移動到App_Code
文件夾。裏面的代碼App_Code/Helper.cshtml
將@helper代碼移動到App_Code文件夾拋出錯誤
@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
是否需要導入任何命名空間或問題出在哪裏?
我想要做的方式是完美的嗎?
Darin,爲什麼我要傳遞Url,如果我可以從RequestContext中提取它,就像我在@ akakey的回覆中發佈的評論一樣? – ekkis 2013-12-22 23:38:13
我不想將currentPage作爲參數傳遞。 @akakey找到了更好的。 – Neshta 2014-09-17 05:59:25
請參閱下面的@akakey答案,它應該被標記爲正確答案 – 2017-11-21 17:13:24