简体   繁体   English

如何在 asp.net 内核 razor 页面 MVVM 之间传递或引用 model

[英]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.

相关问题 有没有什么简单的方法可以将复杂对象从一个 PageModel 文件传递​​到 asp.net 核心剃刀页面(mvvm,而不是 mvc)中的另一个? - Is there any easy way to to pass complex objects from one PageModel file to another in asp.net core razor pages (mvvm, not mvc)? Model 绑定在 ASP.NET 核心 Razor 页 - Model Binding in ASP.NET Core Razor Pages 在razor,asp.net Core 2.2页面之间传递值 - Passage of values ​between pages razor, asp.net Core 2.2 如何使用剃刀页面在 ASP.Net Core 上将对象从一个页面传递到另一个页面? - How pass objects from one page to another on ASP.Net Core with razor pages? 如何在 ASP.NET Core Razor Pages 部分标签助手中动态传递名称属性? - How to pass name attribute dynamically in ASP.NET Core Razor Pages partial tag helper? 如何仅为 ASP.Net Core Razor 页面中的一个 Model 启用 ModelState 验证? - How enable ModelState validation just for one Model in ASP.Net Core Razor Pages? ASP.NET Core 2.2 Razor页面MVVM查询AspNetUsers和AspNetRoles表 - ASP.NET Core 2.2 Razor Pages MVVM Query the AspNetUsers and AspNetRoles Tables ASP.NET Core Razor页面的路由 - Routing for ASP.NET Core Razor Pages Razor Pages 中的 Asp.net 核心本地化 - Asp.net core Localization in Razor Pages 如何在 ASP.Net Core Razor 页面上重定向 - How to redirect on ASP.Net Core Razor Pages
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM