开发者

Call method with void return type in databinding expression

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 ""; })() %>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜