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

[Solved] Javascript in Telerik methods

1 Answer 27 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jason
Top achievements
Rank 1
Jason asked on 18 Oct 2011, 07:36 PM
I am trying to use a javascript variable to specify which Telerik theme I want to use:

<script type="text/javascript">
        var path = "~/Content/2011.2.712";
        var theme = "telerik.webblue.min.css";
        function setTheme() {
            @{
                Html.Telerik().StyleSheetRegistrar().DefaultGroup(group => group
                    .DefaultPath("~/Content/2011.2.712")
                    .Add("telerik.common.min.css")
                    .Add("'" + @:theme + "'")
                    .Combined(true)
                    .Compress(true))
                    .Render();
                }
        }
    </script>
I have tried many variations on the .Add("'" + @:theme + "'") above, but none with any success. For example, the following results in an error stating, "Cannot convert lambda expression to type 'string' because it is not a delegate type
", which I found strange, since a string is all I am using when I state the filename directly (which does work):
.Add(@<text>theme</text>)
If anyone could help me out and suggest a way that I can use that javascript variable to specify my theme, I would appreciate it

1 Answer, 1 is accepted

Sort by
0
Jason
Top achievements
Rank 1
answered on 19 Oct 2011, 03:23 PM
From what I can tell, what I was trying to do isn't possible.
To get a similar effect (dynamically loaded theme/skin), this is what I had to do:
1. Create a ViewModel for my LayoutPage that contains a variable string 'theme' in its constructor:
public class LayoutModel
    {
        public string theme { get; set; }
 
        public LayoutModel()
        {
            this.theme = "telerik.webblue.css";
        }
    }
        }
    }

2. Ensure all other Models that are used in View pages inherit that ViewModel
3. In my LayoutPage, I now have the following:
<span style="background:yellow;">@{</span>
        Html.Telerik().StyleSheetRegistrar().DefaultGroup(group => group
            .DefaultPath(<span style="color:#a31515;">"~/Content/2011.2.712"</span>)
            .Add(<span style="color:#a31515;">"telerik.common.min.css"</span>)
            .Add(@Model.theme)
            .Combined(<span style="color:blue;">true</span>)
            .Compress(<span style="color:blue;">true</span>)
        ).Render();
    <span style="background:yellow;">}</span>

@Model.theme works correctly.

Hope that helps someone else,
Jason
Tags
General Discussions
Asked by
Jason
Top achievements
Rank 1
Answers by
Jason
Top achievements
Rank 1
Share this question
or