简体   繁体   中英

how to pass or reference model between asp.net core razor pages MVVM

My MVVM core 3.1 Index page displays database data nicely from it's model using this directive:

 @model IndexModel

I launch a second page 'TOCPrintable" (for printing the exact same data but styled differently) with this:

<form method="post">
    <input type="submit" value="Print TOC" asp-page="TOCPrintable" target="_blank"/>
</form>

The problem: I am unable to pass or reference the IndexModel of the Index page and consume it in the TOCPrintable page.

My reason for referencing/passing the model to the second page is I want to avoid coding the same database connections, calls, objects, etc.

IS my approach wrong?

Passing data between pages, or State Management as it is known can be done in a number of ways: https://www.learnrazorpages.com/razor-pages/state-management

In your example, since you are already posting a form, you may as well use hidden form fields.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM