先上代码
需要继承WebViewPage 或 WebViewPage<T>
using System.Web.Mvc;
namespace Library
{
public abstract class Library : WebViewPage
{
public HtmlHelper Fish { get; set; }
public override void InitHelpers()
{
base.InitHelpers();
Fish = new HtmlHelper(ViewContext, this);
}
}
public abstract class Library<TModel> : WebViewPage
{
public HtmlHelper<TModel> Fish { get; set; }
private ViewDataDictionary<TModel> _viewData;
public override void InitHelpers()
{
base.InitHelpers();
Fish = new HtmlHelper<TModel>(ViewContext, this);
}
protected override void SetViewData(ViewDataDictionary viewData)
{
_viewData = new ViewDataDictionary<TModel>(viewData);
base.SetViewData(_viewData);
}
public new TModel Model
{
get
{
return ViewData.Model;
}
}
public new ViewDataDictionary<TModel> ViewData
{
get
{
if (_viewData == null)
{
SetViewData(new ViewDataDictionary<TModel>());
}
return _viewData;
}
set
{
SetViewData(value);
}
}
}
}
mvc页面使用方法
@inherits Library.Library<object>
@Fish.TextBox("text")
网友评论