Is it possible to call a void returning method in a databinding express开发者_C百科ion? (To set a global variable, for example.)
The following doesn't compile:<%# setCurrent(false) %> // Error: Cannot implicitly convert type 'void' to 'object'
I could change the return type of the method (e.g. have it return a null object), but that would be cheating.
The whole point of databinding is that a value is returned for display. (hence the error)
Just return an empty string :)
I think putting a semicolon after your statement should make it semantically correct:
setCurrent(false);
That's not "databinding" per se, but it works.
This isn't terribly elegant, but gets the job done:
<%# new Func<string>(() => { SomeVoidMethod(); return ""; })() %>
精彩评论