我编写了自定义HTML助手,它使用了@Html.ActionLink
,这显然无效,因为代码在App_Code中。然后我提到了这个链接
Using MVC HtmlHelper extensions from Razor declarative views
并将我的帮助改为:
@inherits MVCWebApp.Helpers.CustomHelperPage
@using System.Web.Mvc.Html
@using System.Web.Mvc
@helper GetPager(string action, string controller, int NoOfPagesToGenerate)
{
//implementation
}
这是CustomPageHelper:
using System.Web.WebPages;
using System.Web.Mvc;
namespace MVCWebApp.Helpers
{
public class CustomHelperPage : System.Web.WebPages.HelperPage
{
public static new HtmlHelper<object> Html
{
get { return ((System.Web.Mvc.WebViewPage)WebPageContext.Current.Page).Html; }
}
}
}
有人可以告诉我上面的代码在做什么以及它是如何工作的?
答案 0 :(得分:0)
这有帮助吗?
HtmlHelper _html = new HtmlHelper(
new ViewContext(ControllerContext
, new WebFormView(ControllerContext, "dummy")
, new ViewDataDictionary()
, new TempDataDictionary()
, writer)
, new ViewPage());