asp.net-mvc - 当我从控制器返回 mvc 中的视图时出错
问题描述
我的控制器中有一个方法,它将一个布尔变量作为可选参数(这应该是可选的,不是强制性的),尽管当我返回视图时它说视图需要一个参数。
我有我的模型视图,它将 bool 设置为 true 或 false,以便在确实发生某个操作时在视图中显示错误消息。
这是我的代码
public ActionResult Index([Optional] bool cameFromModal)
{cameFromModal = false;
if (cameFromModal == true)
{
vm.Error = true; // I set the bool to the model so that I can display an error message on my returned view
}
return View(vm);
}
解决方案
也许你可以试试这个;
public ActionResult Index(bool cameFromModal=false)
{
if (cameFromModal == true)
{
vm.Error = true;
}
return View(vm);
}
当您触发 true 时,它会出错
推荐阅读
- flutter - 在 Flutter CupertinoTabBar + StreamBuilder 中,代码正在运行,但未重建小部件
- shopify - Shopify API 获取总退货/退款
- c# - 从数据库中获取几个值并将它们放入 LIst
- javascript - 为什么单击复选框时未选中我的复选框,但链接的文本变为绿色?
- html - 从文本框中的 iframe 获取数据
- c# - 通过搜索字符串获取特定行
- android - 尝试获取应用程序快捷方式时出现“呼叫者无法访问快捷方式信息”异常
- sql - 尝试为我的 SQL 查询找到更好的写作方式
- docker - 使用 docker 时应该在哪里配置 SSL?
- php - 如何为非注册用户生成唯一 ID?