如何创建视图并保存在MVC中的会话中输入的数据 [英] How can I create a view and save the data entered in a session in MVC

查看:100
本文介绍了如何创建视图并保存在MVC中的会话中输入的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。我忙于一个应用程序,但我被卡住了。我需要用户输入他们的交付详细信息,然后将这些详细信息保存在会话[]中。有人能帮我吗?只是在Session []中存储该信息的基本代码。我是否需要SQL数据库,或者我可以使用会话存储吗?如果你需要什么,只说。

谢谢



我尝试过:



我试过在网站上找到它,但没有网站与我需要的相关性。

Hi all. I am busy with an app, but I am stuck. I need the users to enter their delivery details and then save those details in a Session[""]. Can someone help me? Just the basic code of storing that info in Session[""]. Do I require a SQL database for this or can I just use the session storage? If you need anything just say.
thanks

What I have tried:

I tried finding it on websites but no website is to the relevance that I need it.

推荐答案

在View上输入的数据应存储在一个模型。该模型本身可以存储在Session [DeliveryModel]中并从该Session中检索。



The data that is entered on the View should be stored in a Model. That Model itself can be stored in Session["DeliveryModel"] and retrieved from that Session as well.

[HttpPost]
public ActionResult DeliveryInfoSave(DeliveryInfoModel dim) {
  Session["Dim"] = dim;
  return RedirectToAction("DeliveryInfoRetrieve");
}

[HttpGet]
public ActionResult DeliveryInfoRetrieve() {
  DeliveryInfoModel dim = Session["Dim"] as DeliveryInfoModel;
  return View(dim);
}





您也可以将该模型保存到SQLite或内存数据库(如SQL CE)中。我自己更喜欢ADO并转到Sql Server



You could also save that Model into SQLite or an in-memory DB such as SQL CE. I myself prefer to us ADO and go to Sql Server


这篇关于如何创建视图并保存在MVC中的会话中输入的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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