我正在尝试在ASP.NET MVC中创建一个辅助函数,并将模型及其一个属性作为参数传递。我正在尝试模仿我正在处理的这个项目中已经存在的一些其他辅助函数,但是我一直在遇到Context错误。
编辑:
以下是我要创建的帮助功能:
public static MvcHtmlString PreviousPage(this HtmlHelper helper, IPagedList<QuestionAnswerModel> Answers, int pageCount)
{
var tag = new TagBuilder("link");
tag.MergeAttribute("rel", "prev");
return MvcHtmlString.Create(tag.ToString());
}
我正在尝试使用Razor在查看中访问此帮助器:
@{ @Html.PreviousPage(Model.Answers, Model.Answers.PageCount) }
编辑:
以下是我收到的错误,它来自我上面的观看代码:
编译错误
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1061: 'HtmlHelper<QuestionAnswersModel>' does not contain a definition for 'PreviousPage' and no extension method 'PreviousPage' accepting a first argument of type 'HtmlHelper<QuestionAnswersModel>' could be found (are you missing a using directive or an assembly reference?)
我知道这种语法不正确,但我知道我的模型是正确的,并且这些属性是正确定义的。
非常感谢任何帮助!