This is a migrated thread and some comments may be shown as answers.

[Solved] Using TreeView in Html helper extension

1 Answer 147 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Tx3
Top achievements
Rank 1
Tx3 asked on 28 Jun 2010, 10:10 AM
Hi,

I noticed that my View was getting too complicated and I created my own html helper where I am using Telerik TreeView. Everything works like earlier, but I have problems understanding how Content works. Earlier I had:

<%    
    Html.Telerik().Grid<AttributeRow>()  
        .Name("Attributes")  
        .BindTo(Model.Rows)  
        .Columns(columns => 
        {  
            columns.Add(o => { %> 
                <%= ParameterHelper.GetFamilyIndicator(o.IsFromFamily) %> 
                <%= Html.Hidden("AttributeId", o.AttributeId.ToString(), AttributeGridHelper.OtherColumnsHtmlAttributes(o.IsFromFamily, o.AttributeScope))%>   
                <%= Html.Hidden("AttributeName", o.Name, AttributeGridHelper.OtherColumnsHtmlAttributes(o.IsFromFamily, o.AttributeScope))%> 
                <%= Html.Hidden("AttributeValueId", o.AttributeValueId.ToString(), AttributeGridHelper.OtherColumnsHtmlAttributes(o.IsFromFamily, o.AttributeScope))%> 
                <%= Html.Hidden("AttributeTypeId", (int)o.AttributeTypeId, AttributeGridHelper.OtherColumnsHtmlAttributes(o.IsFromFamily, o.AttributeScope))%> 
                <% }).HtmlAttributes(new {style = "width:1px;"});  
            columns.Add(o => o.Name).Title("Name"); 

and I was able to have visible data and also those hidden fields. I converted this to following helper:

        public static MvcHtmlString AttributeEditor<TModel>(this HtmlHelper<TModel> htmlHelper, ParameterCreateViewModel model, string url)  
        {  
            string tmp = string.Empty;  
            htmlHelper.Telerik().Grid<AttributeRow>()  
                .Name("Attributes")  
                .BindTo(model.Rows)  
                .Columns(columns => 
                {  
                    columns.Add(o => {  
                        ParameterHelper.GetFamilyIndicator(o.IsFromFamily);  
                        htmlHelper.Hidden("AttributeId", o.AttributeId.ToString(), AttributeGridHelper.OtherColumnsHtmlAttributes(o.IsFromFamily, o.AttributeScope)).ToString();  
                        htmlHelper.Hidden("AttributeName", o.Name, AttributeGridHelper.OtherColumnsHtmlAttributes(o.IsFromFamily, o.AttributeScope)).ToString();  
                        htmlHelper.Hidden("AttributeValueId", o.AttributeValueId.ToString(), AttributeGridHelper.OtherColumnsHtmlAttributes(o.IsFromFamily, o.AttributeScope)).ToString();  
                        htmlHelper.Hidden("AttributeTypeId", (int)o.AttributeTypeId, AttributeGridHelper.OtherColumnsHtmlAttributes(o.IsFromFamily, o.AttributeScope)).ToString();  
                    }).HtmlAttributes(new {style = "width:1px;"});  
                    columns.Add(o => o.Name).Title("Name"); 

My problem is that I always get the first line which is the ParameterHelper.GetFamilyIndicator... How can I get same results like in the original implementation?

Another question.. Even if I return string.Empty from my helper still TreeView is rendered. Is Render method responsible for that. What kind of magic have you used? :)

-Tatu

1 Answer, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 28 Jun 2010, 11:05 AM
Hello Tx3,

The provide code snippets do not indicate the reason for the erroneous behavior. I suggest you open a support ticket and attach a simple project showing the problem you are facing.

The other option is to try using the provided source code and use the debugger to peek into the executed code.

Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
TreeView
Asked by
Tx3
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Share this question
or