MVC3 将消息从一个控制器传递到另一个视图和/或控制器
我有一个 MVC3 C#.Net Web 应用程序。具有从 Excel 导入功能。此功能在速率控制器的导入方法中执行。它可以在“速率/导入”视图中查看。导入时,有些行成功,有些行不成功。我将错误收集到 string[] 数组中。如果成功导入一行或多行,则导入被视为成功,因此应用程序将导航回“提案编辑”视图。我想将信息错误传递回提案编辑视图以进行显示。任何IDE如何做到这一点?
I have an MVC3 C#.Net web app. that has an import from Excel function. This function is performed in the Import method of the Rate controller. It is viewed in the Rate/Import view. When importing, some rows are successful, some are not. I am gathering the errors into a string[] array. The import is considered successful if one or more rows is successfully imported, therefore the app navigates back to the Proposal Edit view. I want to pass the informational errors back to the Proposal Edit view for display. Any ides how to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有几种方法。
TempData
这在您的控制器中可用。 TempData 在单个重定向中持续存在。
ModelState
您可以将这些错误直接添加到 ModelState,然后重新显示编辑表单。它不会在重定向后持续存在。
然后,在编辑视图中,仅显示验证摘要:
这将呈现此 html。该类是 MVC 设置的默认类。
There are several ways.
TempData
This is available in your controller. TempData persists across a single redirect.
ModelState
You could add these errors directly to the ModelState and then redisplay the edit form. It doesn't persist across a redirect.
Then, in your edit view, just display the validation summary:
This will render this html. The class is the default one set by MVC.