我有以下代碼在Razor視圖中用於配置DevExpress GridView MVC擴展的網格設置。所有代碼都很好,但現在我希望從網格中輸出數據,這需要在'服務器'上需要相同的配置代碼,即視圖的上游。如果不是對WebViewPage<TModel>.ViewContext
屬性的必需訪問權限,我可以很輕鬆地完成此操作並在我的視圖模型上提供GridSettings屬性。如何避免重複此網格配置代碼?
現在我正在使用一個非常醜陋的解決方法,並將ViewContext
從視圖中傳回控制器;控制器然後建立網格設置。不用說在控制器上調用方法的觀點是相當臭的。
settings.Columns.Add(column =>
{
column.Caption = "#";
column.SetDataItemTemplateContent(c =>
{
ViewContext.Writer.Write(
Html.ActionLink("Edit", "Edit", new {id = DataBinder.Eval(c.DataItem, "Id")}) + " " +
Html.ActionLink("Delete", "Delete", new {id = DataBinder.Eval(c.DataItem, "Id")},
new {onclick = "return confirm('Do you really want to delete this record? [Just say no!]')"})
);
});
column.SetHeaderTemplateContent(c => ViewContext.Writer.Write(Html.ActionLink("New", "Create")));
column.Settings.AllowDragDrop = DefaultBoolean.False;
column.Settings.AllowSort = DefaultBoolean.False;
column.Width = 70;
});
settings.Columns.Add("RefNum", "Emp. No.");
錯誤:「&NBSP」應爲「 」 – usr
@usr,好笑的是,我從來沒有發現錯誤,謝謝,因爲Chrome瀏覽器插入一個空格,即使沒有空間默認樣式空格''標籤僅夠沒有注意到。 – ProfK