aspnet / live.asp.net

Code for live.asp.net, which hosts the ASP.NET Community Stand-up
https://live.asp.net/
MIT License
289 stars 114 forks source link

ClickToShowTagHelper as for issue #21 #49

Closed matsprea closed 4 years ago

matsprea commented 9 years ago

ClickToShowTagHelper as for issue #21

DamianEdwards commented 9 years ago

I'd like the Tag Helper to also handle the JavaScript rather than the view having to do it. That means it needs to emit a script block that adds the jQuery event handlers, and it needs to only emit it once, and it needs to done in such a way that all instances of the Tag Helper are found (e.g. script runs on document load event).

DamianEdwards commented 9 years ago

:watch:

matsprea commented 9 years ago

What about using a BodyTagHelper to check if we need to inject the js at the end of the page ?

I'm sorry, the last commit does not work as intended, I'll check it right now.

DamianEdwards commented 9 years ago

@matsprea using a BodyTagHelper is probably a good way of doing this.

DamianEdwards commented 9 years ago

:watch:

matsprea commented 9 years ago

I tried JavaScriptResources.GetEmbeddedJavaScript but I always end up with the following exception, so I end up using GetManifestResourceStream. Sorry, I clearly miss something here.

ArgumentNullException: Value cannot be null.
 Parameter name: stream
System.IO.StreamReader..ctor(Stream stream, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize, Boolean leaveOpen)
System.IO.StreamReader..ctor(Stream stream)
Microsoft.AspNet.Mvc.TagHelpers.Internal.JavaScriptResources.<>c__DisplayClass3_0.<GetEmbeddedJavaScript>b__0(String key)
System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
Microsoft.AspNet.Mvc.TagHelpers.Internal.JavaScriptResources.GetEmbeddedJavaScript(String resourceName, Func`2 getManifestResourceStream, ConcurrentDictionary`2 cache)
Microsoft.AspNet.Mvc.TagHelpers.Internal.JavaScriptResources.GetEmbeddedJavaScript(String resourceName)