Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Can not pass nullable to ViewComponent Invoke method #3211

Closed
RiteshPahwa opened this issue Sep 26, 2015 · 7 comments
Closed

Can not pass nullable to ViewComponent Invoke method #3211

RiteshPahwa opened this issue Sep 26, 2015 · 7 comments
Assignees
Milestone

Comments

@RiteshPahwa
Copy link

Beta7 Calling a method like:

 public async Task<IViewComponentResult> InvokeAsync(int id, bool? commentAllowed, int? commentCount)

Generates error

InvalidOperationException: Could not find an 'Invoke' or 'InvokeAsync' method matching the parameters.

Microsoft.AspNet.Mvc.ViewComponents.DefaultViewComponentInvoker.<InvokeAsync>d__4.MoveNext()

From View as

@await Component.InvokeAsync("Comment", Model.Id, Model.CommentAllowed, Model.CommentCount) 
@Eilon Eilon assigned kichalla and pranavkm and unassigned kichalla Sep 29, 2015
@Eilon
Copy link
Member

Eilon commented Sep 29, 2015

@pranavkm can you investigate?

@RiteshPahwa
Copy link
Author

@pranavkm let me know if you need any help from my side.

This is the page where I wanted to add this functionality
https://github.com/RiteshPahwa/AspNetBlog/blob/master/src/ASPNetBlog/ViewComponents/CommentViewComponent.cs

Thanks, Ritesh

@pranavkm
Copy link
Contributor

@Eilon Eilon added this to the 6.0.0-rc1 milestone Sep 30, 2015
@Eilon
Copy link
Member

Eilon commented Sep 30, 2015

Ok looks like this might be a real bug, moving to RC.

@rynowak
Copy link
Member

rynowak commented Sep 30, 2015

Yeah, we might need to do something smarter than what we're doing, or provide a richer API for invoking viewcomponents.

@pranavkm
Copy link
Contributor

pranavkm commented Oct 5, 2015

There's a relatively easy for this issue.
However the method resolution is broken when one the arguments to the ViewComponentHelper is null. http://stackoverflow.com/questions/5968860/handle-null-parameters-while-calling-a-method-using-reflection highlights the problem. The workaround seems to be to write a custom binder to do method selection that works with null value.

@pranavkm
Copy link
Contributor

pranavkm commented Oct 5, 2015

Discussed the bug from #3211 (comment) offline with @rynowak and @Eilon. I'll patch the ability to invoke Invoke \ InvokeAsync with nullable values, however we'll currently not support passing in null values to these methods. @rynowak will update a follow up work item to revisit ViewComponent method selection.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants