c# - MVC6 ViewComponents Simple Example results in "Could not find an 'Invoke' method matching the parameters." -
i trying figure out new viewcomponents feature in simplest sense , having trouble , lack of documentation not helping.
my first goal invoke viewcomponent list of strings , have them displayed.
the literally guide can find viewcomponents here , have based off of far: http://www.asp.net/vnext/overview/aspnet-vnext/vc#intro
i want display list of strings pass in invoke method, can't seem invoke method work in first place.
my folder/file structure is:

my simple code follows:
vcexampleviewcomponent.cs
using microsoft.aspnet.mvc; namespace mvc6example3.viewcomponents { public class vcexampleviewcomponent : viewcomponent { public vcexampleviewcomponent() { } public iviewcomponentresult invoke(string[] strarr) { return view(strarr); } } } default.cshtml (what viewcomponent supposed rendering)
@model string[] <h3>strings passed in:</h3> @foreach (string str in model) { <span>@str</span> } index.cshtml (where viewcomponent invoked)
@{ viewbag.title = "home page"; } <div class="jumbotron"> <h1>viewcomponent example</h1> </div> @component.invoke("vcexample", new string[]{"hello", "hola", "bonjour" }) the error is:
500 internal server error
system.invalidoperationexception
could not find 'invoke' method matching parameters.
at microsoft.aspnet.mvc.viewcomponents.defaultviewcomponentinvoker.invoke(viewcomponentcontext context) @ microsoft.aspnet.mvc.viewcomponents.defaultviewcomponenthelper.invokecore(textwriter writer, viewcomponentdescriptor descriptor, object[] arguments) @ microsoft.aspnet.mvc.viewcomponents.defaultviewcomponenthelper.invoke(string name, object[] arguments) @ asp.aspv__views_home_index_cshtml.d__13.movenext() in /views/home/index.cshtml:line 9
it trivial overlooked can't seem find it. help!
Comments
Post a Comment