You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 14, 2018. It is now read-only.
I have a simple view component.
[ViewComponent(Name ="MyViewComponent")]
public class SimpleViewComponent : ViewComponent
{
public IViewComponentResult Invoke(int num)
{
return View(num);
}
}
I called this view component from normal cshtmls as follows: @await Component.InvokeAsync("MyViewComponent", 42)
And, it triggered the following error:
System.InvalidOperationException: The model item passed is null, but this ViewDataDictionary instance requires a non-null model item of type 'System.Int32'.
at Microsoft.AspNet.Mvc.ViewDataDictionary1.SetModel(Object value) at Microsoft.AspNet.Mvc.ViewDataDictionary..ctor(ViewDataDictionary source, Object model) at Microsoft.AspNet.Mvc.ViewDataDictionary1..ctor(ViewDataDictionary source, Object model)
at Microsoft.AspNet.Mvc.ViewComponent.View[TModel](String viewName, TModel model)
at Microsoft.AspNet.Mvc.ViewComponent.View[TModel](TModel model)
at HelloHelpers.Components.SimpleViewComponent.Invoke(Int32 num) in C:\Users\yjhong\Documents\Visual Studio 14\Projects\HelloHelpers\src\HelloHelpers\Components\SimpleViewComponent.cs:line 13
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNet.Mvc.DefaultViewComponentInvoker.InvokeSyncCore(MethodInfo method, ViewContext context)
at Microsoft.AspNet.Mvc.DefaultViewComponentInvoker.d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNet.Mvc.DefaultViewComponentHelper.d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNet.Mvc.DefaultViewComponentHelper.d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
The text was updated successfully, but these errors were encountered:
The problem is with value types as the model type. VDD tries to copy the VDD of the controller, and then encounters an error during construction because it tries to assign the model of the controller (which is null).
I have a simple view component.
[ViewComponent(Name ="MyViewComponent")]
public class SimpleViewComponent : ViewComponent
{
public IViewComponentResult Invoke(int num)
{
return View(num);
}
}
I called this view component from normal cshtmls as follows:
@await Component.InvokeAsync("MyViewComponent", 42)
And, it triggered the following error:
System.InvalidOperationException: The model item passed is null, but this ViewDataDictionary instance requires a non-null model item of type 'System.Int32'.
at Microsoft.AspNet.Mvc.ViewDataDictionary
1.SetModel(Object value) at Microsoft.AspNet.Mvc.ViewDataDictionary..ctor(ViewDataDictionary source, Object model) at Microsoft.AspNet.Mvc.ViewDataDictionary
1..ctor(ViewDataDictionary source, Object model)at Microsoft.AspNet.Mvc.ViewComponent.View[TModel](String viewName, TModel model)
at Microsoft.AspNet.Mvc.ViewComponent.View[TModel](TModel model)
at HelloHelpers.Components.SimpleViewComponent.Invoke(Int32 num) in C:\Users\yjhong\Documents\Visual Studio 14\Projects\HelloHelpers\src\HelloHelpers\Components\SimpleViewComponent.cs:line 13
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNet.Mvc.DefaultViewComponentInvoker.InvokeSyncCore(MethodInfo method, ViewContext context)
at Microsoft.AspNet.Mvc.DefaultViewComponentInvoker.d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNet.Mvc.DefaultViewComponentHelper.d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNet.Mvc.DefaultViewComponentHelper.d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
The text was updated successfully, but these errors were encountered: