如何在httppost上的视图上显示viewbag [英] How to display viewbag on view on httppost

查看:73
本文介绍了如何在httppost上的视图上显示viewbag的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够在按钮点击事件的视图上显示ViewBag,这是我的代码:



 [HttpPost] 
public ActionResult SpecificWorkflowReport(Report2ListViewModel wf)
{

var getSpRecord = db.Mworkflow()。ToList();

var getRecord =(来自u在getSpRecord
中选择新的Report2ListViewModel
{
WorkFlowType = u.WorkFlowType,
WorkflowInstanceId = u.WorkflowInst,
WorkFlowDescription = u.WorkFlowDesc,
})。ToList();

ViewBag.WorkflowType = wf.WorkFlowType;
ViewBag.WorkflowInstanceId = wf.WorkflowInst;
ViewBag.WorkFlowDescription = wf.WorkFlowDesc

var data = Newtonsoft.Json.JsonConvert.SerializeObject(getRecord);
返回Json(数据);
}





我的尝试:



Worflow类型:@ ViewBag.WorkflowType

工作流程实例ID:@ ViewBag.WorkflowInstanceId

工作流程描述:@ ViewBag.WorkFlowDescription





ViewBag值在视图中始终为空,任何帮助都将受到赞赏。

解决方案

每次请求都会重新初始化viewbag。您必须找到一种不同的方法来在请求之间保留数据。有几种方法可以做到这一点,您使用哪种方法实际上取决于您的要求。谷歌是你的朋友。



mvc在请求之间保持数据 - Google搜索 [ ^ ]

i want to be able to display the ViewBag on the view on button click event, this is my code:

[HttpPost]
public ActionResult SpecificWorkflowReport(Report2ListViewModel wf)
{

      var getSpRecord = db.Mworkflow().ToList();

      var getRecord = (from u in getSpRecord
       select new Report2ListViewModel
          {
            WorkFlowType = u.WorkFlowType,
            WorkflowInstanceId = u.WorkflowInst,
            WorkFlowDescription = u.WorkFlowDesc,
          }).ToList();

          ViewBag.WorkflowType = wf.WorkFlowType;
          ViewBag.WorkflowInstanceId = wf.WorkflowInst;
          ViewBag.WorkFlowDescription = wf.WorkFlowDesc

          var data = Newtonsoft.Json.JsonConvert.SerializeObject(getRecord);
          return Json(data);
}



What I have tried:

Worflow Type: @ViewBag.WorkflowType
Workflow Instance Id: @ViewBag.WorkflowInstanceId
Workflow Description: @ViewBag.WorkFlowDescription


the ViewBag values are always null on the view, any assistance will be appreciated.

解决方案

The viewbag is re-initialized with each request. You have to find a different way to persist data between requests. There are several ways you can do this, and which method you use really depends on your requirements. Google is your friend.

mvc persist dat between requests - Google Search[^]


这篇关于如何在httppost上的视图上显示viewbag的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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