首页 > 解决方案 > 传递给控制器​​的值更改为 null

问题描述

我第一次遇到这个。我已将视图中的值传递给控制器​​,这会产生错误。在检索它的操作上放置断点后,我发现正在检索该值,但是当从 post 操作传递到 get 操作时,它变为 null。知道是什么原因造成的吗?

我的代码如下:

 [HttpPost]
    [ValidateInput(false)]
    public ActionResult reservation_step_1(string x)
    {
        string val = x;
        return RedirectToAction("reservation_step_2", "Home", new { val = val });
    }

    [HttpGet]
    public ActionResult reservation_step_2(string val)
    {
        string rat = val;

        string a = rat.Substring(0, rat.Length - 16);
        string b = a.Substring(2);

        return View();
    }

标签: asp.net-mvc

解决方案


根据对原始帖子的评论,如果您要传递 HTML,听起来您需要将 [ValidateInput(false)] 添加到 reservation_step_2 方法。


推荐阅读