如何从一个页面处理程序发布到另一个? [英] How to POST from one Page Handler to another?

查看:73
本文介绍了如何从一个页面处理程序发布到另一个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Razor Pages(不是MVC)开发ASP.NET Core 2.0项目.

I am working on a ASP.NET Core 2.0 project using Razor Pages (not MVC).

我有以下流程:

  1. 用户填写表格和POST
  2. 此页面的POST处理程序验证信息并在出现问题时返回Page().如果不是,则处理程序将数据保存到数据库.
  3. 在这里,我希望处理程序使用步骤2中经过验证并保存的数据,将其发布到其他页面的POST处理程序中.

我如何从页面处理程序中发布到另一个页面?这是做这种事情的适当方法吗?我不想使用RedirectToPage()的原因是,我不想通过GET来导航序列中的最后一页.最终页面不应通过直接链接访问,而应仅在POST上返回.

How do I POST to another page from within a page handler? Is this the appropriate way to do this kind of thing? The reason I don't want to RedirectToPage() is because I don't want the final page in the sequence to be navigable via GET. The final page should not be accessible via a direct link but should only return on a POST.

我考虑过验证/保存数据并设置一个布尔值"IsValid"并返回页面,检查该IsValid,然后立即通过JS发布到最终页面.但是,这感觉很脏.

I thought about validating/saving the data and setting a boolean "IsValid" and returning the page, checking for that IsValid, and immediately POSTing to the final page via JS. However this feels dirty.

推荐答案

将表单的"asp-page"属性设置为其他页面.然后以标准方式设置值.

Set the "asp-page" property of the form to your other page. Then set values in the standard way.

<form method="post" asp-page="/pathto/otherpage">
Select Example:<select name="DataForOtherPage">

然后在您的控制器中,绑定值...

Then in your controller, bind the value...

 [BindProperty]
 public string DataForOtherPage { get; set; }

这篇关于如何从一个页面处理程序发布到另一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆