c# - 如何从 ASP.NET MVC 中的不同操作返回视图
问题描述
我有一个视图叫做DetailsLane
另一个AddItem
. 渲染时DetailsLane
,它返回一个带有属性的模型类。该AddItem
动作在同一个控制器中,但是当我完成了在该动作中必须做的任何事情时,我无法重新渲染DetailsLane
以更新视图。
第一次调用视图:它有效!
public ActionResult DetailsLane(int? id, int? IdInstance)
{
return View(get(IdInstance, id));
}
public ActionResult AddLine(FormCollection collection)
{
// I did my stuff in here, and I want to return the initial View or,
// validate something from the collection.
return DetailsLane(val, val); // doesn't work!
}
解决方案
您想使用RedirectToAction
并且可以传递参数,如下所示
public ActionResult AddLine(FormCollection collection)
{
// I did my stuff in here, and I want to return the initial View or,
// validate something from the collection.
return RedirectToAction("DetailsLane", new { id = val1, IdInstance = val2 });
}
请注意id
并IdInstance
匹配您的DetailsLane
操作方法中的参数名称。
推荐阅读
- tortoisesvn - 目录上的 TortoiseSVN 差异仅显示 propinfo - 给出了什么?
- google-app-engine - 在 Firebase 托管上将 Ionic 应用程序作为 PWA 运行
- ios - 如何使用更少的内存在 collectionView 中显示照片库
- html - 如何连续渲染 django 博客文章?
- sql - PL/SQL 语句被忽略:缺少表达式
- oracle - 如何将参数从查询传递到子查询?ORA-00904
- database - Laravel Api , 2 类用户, 分开或做一张表
- css - chrome dev-tools 中的元素尺寸与 css 中设置的元素尺寸不同
- node.js - npm 位于 Windows 10 上的两个不同目录中
- android - 从选项卡式活动中的片段更改 FloatingActionButton