asp.net-mvc - 传递给控制器的值更改为 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();
}
解决方案
根据对原始帖子的评论,如果您要传递 HTML,听起来您需要将 [ValidateInput(false)] 添加到 reservation_step_2 方法。
推荐阅读
- c# - 如何使用 selenium 实现下面描述的页面对象模式 C# 代码?
- c# - 阻止 EF 添加或更新某些子实体
- javascript - How to get the value of an observable using knockout
- wordpress - How change default parent page for custom template in wordpress?
- c# - WPF 如何处理自定义集合的 CollectionChanged 事件?
- python - Scrapy 不遵循给定的请求
- android - How to retrieve file path and file name from gallery image to be used for uploading to server?
- ruby-on-rails - `test/dummy/config/application (LoadError)` when using `rails console` in a Rails engine
- python - 如何在每次迭代中仅从一个类中抽取批次
- ios - 如何快速隐藏customView中的按钮