This question is locked. New answers and comments are not allowed.
Got a couple questions regarding the ScriptRegistrar and the StylesheetRegistrar and how they are currently functioning with the new Razor view engine Yes I know it is not supported so if these are no workarounds available I'll just have to accept it.
1) With the aspx view engine you could use an inline template to define your OnDocumentReady JavaScript. You could define it similar to this:
There seems to be no way to do this with Razor at the moment. If you try and use inline templates ala:
You get an exception stating "CS1593: Delegate 'System.Action' does not take 1 arguments". If you use just <text> instead of @<text> you get an error stating "CS1026: ) expected" and it seems to be trying to treat the content as a string.
Now I know you can use a string literal for OnDocumentReady but that really makes it a pain to pop in model values since you're reducded to having to use String.Format(...) to do accomplish this. Am I missing something with regards to the inline templates?
2) My second issue, and perhaps the most pressing, is that the page execution seems to be reversed in Razor. Inline code snippets are executed on the furthest nested view element and then it traverses backwards. This is a problem because normally your master page (or layout in Razor) takes care of all your generic scripts and stylesheets (ie the JQuery library, theme CSS, etc). Now take this scenario: _Layout -> ViewA -> _PartialA -> _PartialB. If _Layout was taking care of registering those base files but then ViewA had just 1 .js file and 1 .css file specific to just that view then it would register it's own specific files as well.
The problem is that since ViewA will be called first its scripts will be registered in the registrar as the first items, then the layout's files will be registered afterwards. This of course would produce unwanted behavior. First of all if ViewA's script may want to be executed only when the page has finished loading so it may use $(document).ready(...) to accomplish this. If it is registered first, as it would be in this scenario, then it wouldn't even know what $ represents yet because it is included in the page prior to the base jquery file. A similar problem exists with CSS because normally you want to override base CSS classes in particular cases and order of precendence depends on the order in which the CSS appears in the document.
This second issue is a huge game breaker for me when it comes to using the registrars in my current work which is using Razor. If I'm doing something wrong please let me know as soon as possible.
Thanks,
Kevin
1) With the aspx view engine you could use an inline template to define your OnDocumentReady JavaScript. You could define it similar to this:
<% Html.Telerik() .ScriptRegistrar() .OnDocumentReady(() => {%> // some javascript here and you could use Model.<Properties> etc since it is a template <%}); %>There seems to be no way to do this with Razor at the moment. If you try and use inline templates ala:
@{ Html.Telerik() .ScriptRegistrar() .OnDocumentReady( @<text> // some javascript here </text> );}You get an exception stating "CS1593: Delegate 'System.Action' does not take 1 arguments". If you use just <text> instead of @<text> you get an error stating "CS1026: ) expected" and it seems to be trying to treat the content as a string.
Now I know you can use a string literal for OnDocumentReady but that really makes it a pain to pop in model values since you're reducded to having to use String.Format(...) to do accomplish this. Am I missing something with regards to the inline templates?
2) My second issue, and perhaps the most pressing, is that the page execution seems to be reversed in Razor. Inline code snippets are executed on the furthest nested view element and then it traverses backwards. This is a problem because normally your master page (or layout in Razor) takes care of all your generic scripts and stylesheets (ie the JQuery library, theme CSS, etc). Now take this scenario: _Layout -> ViewA -> _PartialA -> _PartialB. If _Layout was taking care of registering those base files but then ViewA had just 1 .js file and 1 .css file specific to just that view then it would register it's own specific files as well.
The problem is that since ViewA will be called first its scripts will be registered in the registrar as the first items, then the layout's files will be registered afterwards. This of course would produce unwanted behavior. First of all if ViewA's script may want to be executed only when the page has finished loading so it may use $(document).ready(...) to accomplish this. If it is registered first, as it would be in this scenario, then it wouldn't even know what $ represents yet because it is included in the page prior to the base jquery file. A similar problem exists with CSS because normally you want to override base CSS classes in particular cases and order of precendence depends on the order in which the CSS appears in the document.
This second issue is a huge game breaker for me when it comes to using the registrars in my current work which is using Razor. If I'm doing something wrong please let me know as soon as possible.
Thanks,
Kevin