1
我想獲得HtmlHelper.Display
方法的MvcHtmlString
結果,該方法與我目前的HtmlHelper
不同。下面的代碼編譯,但總是返回一個空字符串。撥打不同型號的HtmlHelper.Display
public static MvcHtmlString GetPropertyValue(this HtmlHelper html, string property, object value)
{
var dictionary = new ViewDataDictionary();
dictionary.Add(property, value);
var fooHelper = new HtmlHelper<FooModel>(
new ViewContext(
html.ViewContext,
new WebFormView(html.ViewContext, "dummy"),
dictionary,
new TempDataDictionary(),
TextWriter.Null),
new ViewPage());
return fooHelper.Display(property);
}
所有輔助對象(ViewContexts
,ControllerContexts
,ViewDataDictionaries
等)類型的黑盒給我;我確定我錯過了一些明顯的東西。
我如何得到這個工作?
對於好奇:這是在我的應用程序審計頁面上使用。我有數據庫中的屬性名稱(作爲string
),舊值和新值。我也知道將用於顯示記錄所代表的模型的實際實例的類型。我想重複使用模型類中的所有數據註釋來顯示HTML。