简体   繁体   English

具有强类型的局部视图的HandleError

[英]HandleError with strongly-typed Partial View

I ran into a small roadblock this morning with HandleError. 今天早上,我因HandleError遇到了一个小障碍。 Users are directed properly to the /Views/Shared/Error.aspx. 将用户正确定向到/Views/Shared/Error.aspx。 This view uses a Master Page which also displays just fine. 此视图使用母版页,它也显示得很好。 It also logs the particulars of the ViewData.Model.Exception in its Page_Load method. 它还在其Page_Load方法中记录ViewData.Model.Exception的详细信息。 An acceptable use of codebehind in my opinion. 我认为可以合理地使用后台代码。

My problem is this: The page contains a strongly-typed Partial View that contains some of the user's input data. 我的问题是:该页面包含一个强类型的Partial View,该视图包含一些用户的输入数据。 I would like to retain access to that data even after the exception occurs - so the user isn't doubly-penalized for our exception (being presented with an error message AND losing their form values). 即使在发生异常之后,我也希望保留对这些数据的访问权-因此,不会因为我们的异常而使用户受到双重惩罚(出现错误消息并丢失其表单值)。

Is there a way to accomplish this using HandleError or another reusable attribute? 有没有一种方法可以使用HandleError或其他可重用属性来完成此任务?

The simplest solution would be the back-button, and it needs no code :-) 最简单的解决方案是后退按钮,它不需要代码:-)

If you need a code-based solution, I think you have to persist your form data before the user land on Error.aspx. 如果您需要基于代码的解决方案,我认为您必须在用户登陆Error.aspx之前保留表单数据。 At that point a redirection has happened and all request-data would be lost. 那时发生了重定向,所有请求数据都将丢失。 Then when the user navigates to the faulty view, you restore the form from the persisted values. 然后,当用户导航到错误视图时,可以从持久值还原表单。

Error.aspx is a general error page, and your last resort. Error.aspx是常规错误页面,也是您的不得已的方法。 This page should not even try to do any task beyond general error handling. 该页面甚至不应尝试执行除常规错误处理之外的任何任务。

The way I get around this problem is to use Ajax.BeginForm(){} and Render the user control that way your view is not refreshed and your input is not lost. 我解决此问题的方法是使用Ajax.BeginForm(){}并以不刷新视图和输入内容的方式呈现用户控件。 If your error messages are strictly input restrictions then you can also use jquery.validate.js file can be found here http://randomactsofcoding.blogspot.com/2008/09/starting-with-jquery-validation-plug-in.html 如果您的错误消息受到严格的输入限制,那么您也可以使用jquery.validate.js文件,可以在此处找到http://randomactsofcoding.blogspot.com/2008/09/starting-with-jquery-validation-plug-in.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM