2015-10-05 65 views
0

我想設置幀標題和我的BeginEditFrame, 自定義按鈕,但我不能將它設置在最後一個方法,玻璃映射 - 爲expirence編輯組按鈕和幀標題

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

爲什麼不能使用最後一個Glass方法?你看到的問題是什麼? –

+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) 
    { 

    } 
}