简体   繁体   English

asp.net mvc或javascript将另一页的结果返回给方法

[英]asp.net mvc or javascript return results of another page to method

Is it possible to have results from another page returned to a JavaScript method or a C# controller action? 是否可以将另一个页面的结果返回给JavaScript方法或C#控制器操作?

I have a shared complex page that's used all over my website that's currently used to set a single variable on the user data in the C# back end. 我有一个共享的复杂页面,该页面在我的网站上遍布使用,当前用于在C#后端的用户数据上设置单个变量。 When the user has finished the shared complex page, I return to the referring page. 当用户完成共享的复杂页面后,我将返回引用页面。 The page that I've returned to contains the newly selected variable when the user returns as it's refreshed or alternatively passed as a url parameter to the returning page. 当用户在刷新或返回时将其作为url参数传递给返回的页面时,我返回的页面包含新选择的变量。

I have a new page where I'd like the variable from my shared complex page to be returned. 我有一个新页面,我希望从我的共享复杂页面中返回该变量。 However there will be multiple instances of this variable on the page and they're actually different data to the previously stored single variable on the user data in the C# back end. 但是,页面上将有该变量的多个实例,它们实际上是与C#后端中用户数据上先前存储的单个变量不同的数据。 ie I'd like to have several buttons on the page that lead to my shared complex page and when the user returns the data for each button will be displayed next to the button. 例如,我想在页面上有几个按钮,这些按钮会导致我共享复杂的页面,并且当用户返回时,每个按钮的数据将显示在按钮旁边。

Is there a way in JavaScript or C# to display another page and have the result returned to the method that instantiated the display of the page? JavaScript或C#中是否可以显示另一页并将结果返回到实例化该页面显示的方法? If my back end was implemented in scheme I'd use a continuation to achieve this result. 如果我的后端是在方案中实现的,那么我将使用延续来实现此结果。 Is there any equivalent in C#? C#中有什么等效的东西吗? I've been looking at async tasks in C# but none of the examples show a user interacting with another page as part of the asynchronous operation. 我一直在看C#中的异步任务,但是没有一个示例显示用户作为异步操作的一部分与另一个页面进行交互。 Is this possible? 这可能吗?

If not I'll have to pass the value back to the new page via URL parameters. 如果没有,我将不得不通过URL参数将该值传递回新页面。 I would like to avoid this because of the amount of contextual data I'd need to pass between the two pages. 我想避免这种情况,因为我需要在两个页面之间传递上下文数据。 I'd thought of using a redirect from the shared complex page to update the new data on the back end before returning to the new page to solve half the problem but this site works on mobile so the network latencies rule out redirects. 我曾想过使用共享的复杂页面上的重定向来更新后端的新数据,然后再返回到新页面以解决一半的问题,但是该站点可以在移动设备上运行,因此网络等待时间可以排除重定向。 Also having the complex shared page as a pop up dialog within the new page won't really work as it's a) complex b) the new page can be used a pop up on an existing page and having a pop up from a pop up is unsupported on Bootstrap. 同样,在新页面中将复杂的共享页面作为弹出对话框并不能真正起作用,因为它是a)复杂b)可以将新页面用作现有页面上的弹出窗口,而从弹出窗口中弹出窗口是Bootstrap不支持。

The sharing of data between web pages, without an established continuation medium, requires the use of a shared state somewhere, like session variables or cookies. 在没有建立连续媒体的情况下,网页之间的数据共享需要在某处使用共享状态,例如会话变量或cookie。 As each page changes the state, it can go back to the server, update that session, and when the process is done, you'd read that session via ajax and complete your process. 当每个页面更改状态时,它可以返回到服务器,更新该会话,并且在完成该过程后,您将通过ajax阅读该会话并完成您的过程。

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

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