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

Cannot pass a int parameter to the views from ViewComponent #1214

Closed
ianhong opened this issue Oct 2, 2014 · 3 comments
Closed

Cannot pass a int parameter to the views from ViewComponent #1214

ianhong opened this issue Oct 2, 2014 · 3 comments
Assignees
Milestone

Comments

@ianhong
Copy link
Contributor

ianhong commented Oct 2, 2014

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)

@ianhong ianhong added the bug label Oct 2, 2014
@danroth27
Copy link
Member

@ianhong @rynowak Is the issue only with int? Do other unboxed types work?

@rynowak
Copy link
Member

rynowak commented Oct 8, 2014

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).

We have another issue that also reported this.

@danroth27 danroth27 added this to the 6.0.0-beta1 milestone Oct 13, 2014
@danroth27 danroth27 assigned rynowak and unassigned yishaigalatzer Oct 14, 2014
@sornaks sornaks assigned sornaks and unassigned rynowak Oct 17, 2014
sornaks pushed a commit that referenced this issue Oct 17, 2014
…ent.

Fix: Checking if the model is not null in the Copy constructor of ViewDataDictionary.
sornaks pushed a commit that referenced this issue Oct 17, 2014
…ent.

Fix: Checking if the model is not null in the Copy constructor of ViewDataDictionary.
@sornaks
Copy link

sornaks commented Oct 17, 2014

Checked in. 5b1bcb6

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