0
votes

I created simple partial view in shared folder. But when i render it in index.cshtml by using partial tag it gives an error.

Error: InvalidOperationException: The model item passed into the ViewDataDictionary is of type 'CoreWeb.Pages.IndexModel', but this ViewDataDictionary instance requires a model item of type 'CoreWeb.Pages.Shared._PartialTestModel'.

I used <partial name="_PartialTest"> tag for rendering

Partial view location

partial view content

Rendering in index.cshtml

Startup.cs file changes related to PartialView

Error

1
Please add errors, html etc. as text instead of images of them - James Z
ok noted for next question :) - Muhammad Maaz Sheikh

1 Answers

0
votes

In the <partial> declaration, you need to pass an appropriate model, in this case, an instance of _PartialTestModel:

<partial name="_PartialTest" model="@new _PartialTestModel()" />

See https://docs.microsoft.com/en-us/aspnet/core/mvc/views/tag-helpers/built-in/partial-tag-helper?view=aspnetcore-3.1.