我想用BeginEditFrame为框架和我的自定义按钮设置标题, 但是我不能在最后一种方法中设置它,
public GlassEditFrame BeginEditFrame();
public GlassEditFrame BeginEditFrame(string dataSource);
public GlassEditFrame BeginEditFrame(string buttons, string dataSource);
public GlassEditFrame BeginEditFrame<T>(T model, string title = null, params Expression<Func<T, object>>[] fields) where T : class;
是否可以设置编辑框架标题?
答案 0 :(得分:3)
我遇到了同样的情况,最终创建了一个派生的EditFrame和自定义扩展来支持标题。
public static class HtmlHelperExtensions
{
/// <summary>
/// An extra extensions because the default ones are bugged or do not expose title
/// </summary>
/// <typeparam name="TModel"></typeparam>
/// <param name="htmlHelper"></param>
/// <param name="model"></param>
/// <param name="buttons"></param>
/// <param name="title"></param>
/// <returns></returns>
public static GlassEditFrame BeginEditFrame<TModel>(this HtmlHelper htmlHelper, TModel model, string buttons, string title = "") where TModel : BaseCommon
{
var output = new HtmlTextWriter(htmlHelper.ViewContext.Writer);
var editFrame = new EditFrame()
{
DataSource = model.Id.ToString(),
Buttons = buttons,
Title = title
};
editFrame.RenderFirstPart(output);
return new CustomGlassEditFrame(editFrame, htmlHelper.ViewContext.Writer);
}
}
/// <summary>
/// Added this fix because were unable to set the Title otherwise..
/// </summary>
public class CustomGlassEditFrame : GlassEditFrame
{
public CustomGlassEditFrame(string buttons, TextWriter writer, string dataSource = "") : base(buttons, writer, dataSource)
{
}
public CustomGlassEditFrame(EditFrame frame) : base(frame)
{
}
/// <summary>
/// Using HtmlHelperExtensions.BeginEditFrame(EditFrame) you will miss the writer in the RenderLastPart, this extra constructor passes the writer
/// </summary>
/// <param name="frame"></param>
/// <param name="writer"></param>
public CustomGlassEditFrame(EditFrame frame, TextWriter writer)
: base(frame.Buttons, writer, frame.DataSource)
{
}
}