简体   繁体   English

在ASP MVC页面之间传递变量而不将其发送到服务器

[英]Passing variables between ASP MVC pages without sending it to server

I am creating a website with ASP.NET MVC 4. The application consists of two pages, whose workflow is similar to Google Maps. 我正在使用ASP.NET MVC 4创建一个网站。该应用程序由两个页面组成,其工作流程类似于Google Maps。 On the first page, the user types in a patient's name, date of birth, and some basic data about that patient. 在第一页上,用户键入患者的姓名,出生日期以及该患者的一些基本数据。 Then the user submits the form, and is brought to the second page in the application. 然后用户提交表单,并被带到应用程序的第二页。 The second page is just a print preview that the user can print. 第二页只是用户可以打印的打印预览。 I want the user to be able to navigate between the two pages using the browser's back and forward buttons (for example, to change inputs on the first page after seeing the second page) 我希望用户能够使用浏览器的后退和前进按钮在两个页面之间导航(例如,在看到第二页后更改第一页上的输入)

Actually calculating the data that appears on the printout is very complicated, and I really want to have all that code be executed server-side, where I can use C#. 实际上计算打印输出上出现的数据非常复杂,我真的希望所有代码都在服务器端执行,我可以使用C#。 So I need to send the patient's data to the server. 所以我需要将患者的数据发送到服务器。 The problem is that I don't have an SSL certificate, and I don't want to send a patient's name with their data over HTTP (as this is a violation of privacy). 问题是我没有SSL证书,我不想通过HTTP发送患者姓名及其数据(因为这违反了隐私)。 I am willing to send the patient's data over HTTP, as long as it remains detached from the patient's identity (except for at the client). 我愿意通过HTTP发送患者的数据,只要它仍然与患者的身份分开(除了在客户端)。 The name and date of birth are simply displayed in the corner of the printout, and do not affect the server-side calculations in the least. 出生的名称和出生日期只显示在打印输出的角落,并且不会影响服务器端的计算。

I can think of two possible ways to accomplish this task. 我可以想到两种可能的方法来完成这项任务。 The first, more preferred solution, would be a way to send only some of the form data over HTTP, yet still somehow get the name and date of birth from the first page in client-side jquery running on the second page. 第一种更优选的解决方案是通过HTTP仅发送一些表单数据的方法,但仍然以某种方式从第二页上运行的客户端jquery的第一页获取出生的名称和出生日期。 Maybe I can make a cookie and somehow specify not to send it as part of the http request? 也许我可以制作一个cookie并以某种方式指定不将其作为http请求的一部分发送?

The other way to accomplish this is to make the entire application into a single page, and dynamically change the contents via client-side jquery. 实现此目的的另一种方法是将整个应用程序放入单个页面,并通过客户端jquery动态更改内容。 In this solution, when the user submits the form, I can fire off an ajax request that will return JSON. 在此解决方案中,当用户提交表单时,我可以触发将返回JSON的ajax请求。 I can then populate the print preview with data returned from the server (ie the JSON) as well as from the form (ie the patient's name and date of birth). 然后,我可以使用从服务器返回的数据(即JSON)以及表格(即患者的姓名和出生日期)填充打印预览。 Is there a way to accomplish this while still allowing the user to use the browser's back and forward commands to navigate between the data input page and the print preview page if they are in fact the same page? 有没有办法实现这一点,同时仍允许用户使用浏览器的后退和前进命令在数据输入页面和打印预览页面之间导航,如果它们实际上是同一页面?

I don't believe what you described is possibly without severe drawbacks. 我不相信你所描述的可能没有严重的缺点。 Sure, you could roll up the data into a cookie or local storage and avoid the POST--but this is a lot of logic in your view, and a pretty nasty hack. 当然,您可以将数据汇总到cookie或本地存储中并避免POST - 但这在您的视图中是很多逻辑,并且是一个非常讨厌的黑客。

The options I would advise are: 我建议的选项是:

  • Get an SSL cert . 获得SSL证书 If that's the driving force behind your approach then spend the $6 to get one. 如果这是你的方法背后的驱动力,那么花6美元买一个。 Seriously. 认真。

  • Keep the print view in the same page as the form; 将打印视图保留在与表单相同的页面中; use css @media types to specify the print styles. 使用css @media类型指定打印样式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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