我有一個nestedGridTemplate包含一個列表中的一個對象。如何加載模型並傳遞給ascx控件?
this.Gridparent.MasterTableView.NestedViewTemplate = new Custom14NestedTemplate(this.model.Material.First());
這叫我的班public class Custom14Template
。
這個類調用:
public void InstantiateIn(System.Web.UI.Control container)
{
var myPage = new Page();
Control c = myPage.LoadControl("~/Custom14/Templates/View.ascx");
container.Controls.Add(c);
var x = new Label();
x.Text = string.Format("qty : {0}.<br />", this.MyMaterial.Quantity);
container.Controls.Add(x);
}
現在,我的ASCX只包含這個:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="View.ascx.cs" Inherits="*snip*.Templates.View" %>
hello there
一切都是正確顯示
[grid start] [item 1 : expanded] hello there qty : 23. [/item 1] [item 2 /] [item 3 /] [/grid]
我想通過我的對象到我的ASCX,從那裏建立我的HTML顯示使用... 舊相當於<%= html.EditorFor() %>
(Asp.Net MVC)。而不是像我的標籤創建元素,並將它們添加到容器(在C#中構建html感覺很痛苦)。這是可行的嗎?怎麼樣?
您應該總結或引用鏈接的文章,因爲鏈接會隨着時間的推移而衰減。 – pinckerman