[英]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:我的 MVVM 核心 3.1 索引页面使用以下指令很好地显示了来自 model 的数据库数据:
@model IndexModel
I launch a second page 'TOCPrintable" (for printing the exact same data but styled differently) with this:我启动了第二页“TOCPrintable”(用于打印完全相同的数据,但样式不同):
<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.问题:我无法传递或引用索引页面的 IndexModel 并在 TOCPrintable 页面中使用它。
My reason for referencing/passing the model to the second page is I want to avoid coding the same database connections, calls, objects, etc.我将 model 引用/传递到第二页的原因是我想避免对相同的数据库连接、调用、对象等进行编码。
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在页面之间传递数据或State 众所周知的管理可以通过多种方式完成: 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.在您的示例中,由于您已经发布了表单,因此您也可以使用隐藏的表单字段。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.