2sic / razor-blade

A pretty awesome library to make work in Razor easier and more productive
MIT License
6 stars 2 forks source link

Enhancement Request - allow .Attr() to accept Edit.TagToolbar() without .ToString() #7

Closed jeremy-farrance closed 3 years ago

jeremy-farrance commented 3 years ago

As previously discussed in a StackOverflow Q/A here, Is there an Elegant way to use Razor Blade to add TagToolbar()?, it seems like a useful enhancement to RazorBlade...

This currently works, but its a bit awkward and non-obvious to use .ToString() to get it to work.

@Tag.Div(item.Title).Attr(Edit.TagToolbar(item).ToString())
                               ^^^^^^^^^^^^^^^^^^^^^^^^

It would be more logical to just expect it to work like this.

@Tag.Div(item.Title).Attr(Edit.TagToolbar(item))

The error you get w/o the .ToString() doesn't make the solution obvious/discoverable:

Error: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 
The best overloaded method match for 'ToSic.Razor.Markup.Tag
<ToSic.Razor.Html5.Div>.Attr(string, object, string)' has some 
invalid arguments at CallSite.Target(Closure , CallSite , Div , Object ) 
at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet]
(CallSite site, T0 arg0, T1 arg1) at ASP._Page_Portals_0_2sxc_Data__Party_Display_wAccordion_cshtml.BuildPartyFeesHtml(Object party) 
in \Portals\0\2sxc\Data\_Party-Display-wAccordion.cshtml:line 225 at
iJungleboy commented 3 years ago

thx, we'll check

iJungleboy commented 3 years ago

I reproduced the scenario and as of now it seems to just work.

My guess this was a bug in a previous version. I'll close for now.