저는 @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, @ akakey의 답장에 내 의견을 게시하면서 RequestContext에서 가져올 수 있다면 왜 URL을 전달하고 싶습니까? – ekkis
currentPage를 매개 변수로 전달하고 싶지 않습니다. @akakey가 더 좋은 것을 찾았습니다. – Neshta
아래 @akakey 대답을 참조하십시오.이 답변은 정답으로 표시되어야합니다. –