简体   繁体   English

在 Dotnet Core 3.1 中将数据从一个 controller 传递到另一个

[英]Passing data from one controller to another in Dotnet Core 3.1

I am a newbie to the whole MVC pattern, stuck with the following issue:我是整个 MVC 模式的新手,遇到以下问题:

I have 2 controllers, PayReqController and PayResController .我有 2 个控制器, PayReqControllerPayResController I am trying to access data from one action of PayReqController to another action of PayResController .我正在尝试将数据从PayResController的一个操作访问到PayReqController的另一个操作。 I have tried using TempData :我试过使用TempData

TempData["tsnpac"] = tsnpac; 

But it doesn't work because we need to redirect to another controller after setting the TempData .但它不起作用,因为我们需要在设置 TempData 后重定向到另一个TempData Also tried using session Session["TSNPAC"] = "TSNPAC";还尝试使用 session Session["TSNPAC"] = "TSNPAC"; to access it to another controller, but it is giving the value as null .将它访问到另一个 controller,但它给出的值是null

My scenario is that in PayReqController , inside an action I have a value which I need to get that in another controller without redirecting to that controller, because my use case is to redirect to some other URL which I get as a response from other service. My scenario is that in PayReqController , inside an action I have a value which I need to get that in another controller without redirecting to that controller, because my use case is to redirect to some other URL which I get as a response from other service.

I am a newbie to the whole MVC pattern, stuck with the following issue:我是整个 MVC 模式的新手,遇到以下问题:

I have 2 controllers, PayReqController and PayResController.我有 2 个控制器,PayReqController 和 PayResController。 I am trying to access data from one action of PayReqController to another action of PayResController, I have tried using TempData TempData["tsnpac"] = tsnpac but it doesn't work because we need to redirect to another controller after setting the tempData.我正在尝试从 PayReqController 的一个操作访问 PayResController 的另一个操作的数据,我尝试使用 TempData TempData["tsnpac"] = tsnpac但它不起作用,因为我们需要在设置 tempData 后重定向到另一个 controller。 Also tried using session Session["TSNPAC"] = "TSNPAC";还尝试使用 session Session["TSNPAC"] = "TSNPAC"; to access it to another controller but it is giving the value as null.将其访问到另一个 controller 但它给出的值是 null。

My Scenario is that in PayReqController, inside an action i have a value which i need to get that in another controller without redirecting to that controller because my use case is to redirect to some other URL which i get as a response from other service. My Scenario is that in PayReqController, inside an action i have a value which i need to get that in another controller without redirecting to that controller because my use case is to redirect to some other URL which i get as a response from other service.

I am a newbie to the whole MVC pattern, stuck with the following issue:我是整个 MVC 模式的新手,遇到以下问题:

I have 2 controllers, PayReqController and PayResController.我有 2 个控制器,PayReqController 和 PayResController。 I am trying to access data from one action of PayReqController to another action of PayResController, I have tried using TempData TempData["tsnpac"] = tsnpac but it doesn't work because we need to redirect to another controller after setting the tempData.我正在尝试从 PayReqController 的一个操作访问 PayResController 的另一个操作的数据,我尝试使用 TempData TempData["tsnpac"] = tsnpac但它不起作用,因为我们需要在设置 tempData 后重定向到另一个 controller。 Also tried using session Session["TSNPAC"] = "TSNPAC";还尝试使用 session Session["TSNPAC"] = "TSNPAC"; to access it to another controller but it is giving the value as null.将其访问到另一个 controller 但它给出的值是 null。

My Scenario is that in PayReqController, inside an action i have a value which i need to get that in another controller without redirecting to that controller because my use case is to redirect to some other URL which i get as a response from other service. My Scenario is that in PayReqController, inside an action i have a value which i need to get that in another controller without redirecting to that controller because my use case is to redirect to some other URL which i get as a response from other service.

I am a newbie to the whole MVC pattern, stuck with the following issue:我是整个 MVC 模式的新手,遇到以下问题:

I have 2 controllers, PayReqController and PayResController.我有 2 个控制器,PayReqController 和 PayResController。 I am trying to access data from one action of PayReqController to another action of PayResController, I have tried using TempData TempData["tsnpac"] = tsnpac but it doesn't work because we need to redirect to another controller after setting the tempData.我正在尝试从 PayReqController 的一个操作访问 PayResController 的另一个操作的数据,我尝试使用 TempData TempData["tsnpac"] = tsnpac但它不起作用,因为我们需要在设置 tempData 后重定向到另一个 controller。 Also tried using session Session["TSNPAC"] = "TSNPAC";还尝试使用 session Session["TSNPAC"] = "TSNPAC"; to access it to another controller but it is giving the value as null.将其访问到另一个 controller 但它给出的值是 null。

My Scenario is that in PayReqController, inside an action i have a value which i need to get that in another controller without redirecting to that controller because my use case is to redirect to some other URL which i get as a response from other service. My Scenario is that in PayReqController, inside an action i have a value which i need to get that in another controller without redirecting to that controller because my use case is to redirect to some other URL which i get as a response from other service.

I tried TempData but different than this approach and it worked.我尝试了 TempData 但与这种方法不同并且它有效。

I serialized my list when storing it in TempData我将列表存储在 TempData 中时对其进行了序列化

AccountController:帐户控制器:

TempData["BiUsers"] = JsonConvert.SerializeObject(users);

(users is an IEnumerable of UserModel) (users 是 UserModel 的 IEnumerable)

And deserialized it in another controller in which I wanted to use that IEnumerable.并在另一个 controller 中反序列化它,我想在其中使用那个 IEnumerable。

HomeController:家庭控制器:

var users = JsonConvert.DeserializeObject<IEnumerable<UserModel>>(TempData["BiUsers"].ToString());

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

相关问题 如何将一个 DotNet Core 3.1 Class 库项目注入另一个 DotNet Core 3.1 Class 库项目 - How to inject one DotNet Core 3.1 Class library project into another DotNet Core 3.1 Class library project 在ASP.NET MVC中将数据从一个控制器传递到另一个 - Passing data from one controller to another in asp.net mvc Dotnet core 3.1:制作一种常用的调用方法 - Dotnet core 3.1: Making one common method to call [dotNET Core]传递 model 以查看 -&gt; 将复选框与其数据以 POST 方法形式绑定 -&gt; 将整个 model 发送到 controller - [dotNET Core]Passing model to view -> bind checkbox with it's data in POST method form -> sending whole model to controller 将Id从一个控制器传递到另一个控制器 - Passing an Id from one controller to another 将 Session 变量从一个 controller 传递到另一个 - Passing Session variable from one controller to another ASP.Net Core 3.1 - 从 Controller 将值传递给部分视图模式? - ASP.Net Core 3.1 - passing value to partial view Modal From Controller? MVC +将值从一个控制器传递到另一个控制器 - MVC + Passing values from one controller to another controller 无法将模型从一个控制器传递到MVC3中的另一个控制器 - Passing an model from one controller to another controller in MVC3 not working 将视图从一个控制器传递到另一控制器的视图 - Passing view from one controller to another controller's view
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM