Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

MVC6 ViewComponent using Anonymous Type as dynamic view model cause "RuntimeBinderException: 'object' does not contain a definition for "

$
0
0

Hi

Using anonymos Types as dynamc paramater  is working in C' 6.0

Example (works in Linqpad):

void Main()
{
	dynamic dyn = new
	{
		Prop ="Hallo World"
	};
	myFunction(dyn);
}

public void myFunction(dynamic dyn)
{
	Console.WriteLine(dyn.Prop);
}

If i try to do this in ASP.net MVC 6 ViewComponent

Controler:

 public IViewComponentResult Invoke(int shortTermId)
        {
            dynamic shortTerm = new 
            {
                Name = "Hallo World",
            };
            return View(shortTerm);
        }

ViewComponent:

@model dynamic<!--left--><div class="vertTextContainer2"><p class="vertical-text2">@Model.Name</p></div>

Bring up an Binding Error


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>