Home > Enterprise >  Calling another page from Edit page throwing exception in Razor Pages
Calling another page from Edit page throwing exception in Razor Pages

Time:11-29

I have edit page like this

enter image description here

i want to clone this page ,i have a clone button in this edit page like this

enter image description here

Given a link to navigate to clonepage something like this

<a asp-page="./RequestFormClone" asp-route-RequestID="@Model.RequestID"  style="margin-bottom: 0; padding: 3px 0px 4px 8px; cursor: pointer;color:black;">
                Clone Request
            </a>

But when i click on the link i am getting this error

InvalidOperationException: The model item passed into the ViewDataDictionary is of type 'ProjectName.Pages.RequestFormCloneModel', but this ViewDataDictionary instance requires a model item of type 'ProjectName.Pages.RequestFormEditModel'.

not really understood what causing this error,since i need to replicate the exact copy of RequestFormEdit, i just created another page RequestFormClone same as RequestFormEdit.

Any help would be appreciated.

Thanks, Teena John

CodePudding user response:

InvalidOperationException: The model item passed into the ViewDataDictionary is of type 'ProjectName.Pages.RequestFormCloneModel', but this ViewDataDictionary instance requires a model item of type 'ProjectName.Pages.RequestFormEditModel'.

That is because your page and PageModel does not match with each other.

Please check your PageModel name, keep the same with what you define @model in razor page.

That is to say, if you create a PageModel like below:

public class RequestFormCloneModel: PageModel   //PageModel name
{//...}

Your razor page should be like below:

@page
@model RequestFormCloneModel      //model name
  • Related