如何保存无效数据?
How to save invalid data?
We need to create a program that collects runsheets and other form data.
All the forms need to be saved as they're typed, unless explicitly discarded, even the form field data is invalid.
The user should always be able to 'Save for later', or just shut off his window, and data should be saved.
The problem is I'm gonna have to have all the runsheets indexed and searchable, including the invalid ones.
I'm looking at few options:
- Have a subclass of the same type that implements the validation (will that work?)
- Serialize the invalid records as XML and store it somewhere else until its validated and saved permanently.
- Not use validation attributes, but just custom validation (i.e. using
IValidatableObject
interface), that will bypass validation if another 属性 on the record indicates that validation should be skipped, but then I might end up with a lot of data in the database in the same table, maybe this is not a problem as long as I'm control. I'm really considering this option the most.
My real doubt is:
- If I store data elsewhere, searching will be a nightmare
- If I make the validation in an external runtime method, avoiding the use of validation attributes, the columns in the database won't reflect the real 属性 requirements (i.e. required fields).
I think I'll go for this option, because having to search two tables bothers me more, and also because indeed the columns won't be so strict, but I can still set their MaxLength
and some other vital properties that are vital for the database structure but do not really disturb the validation process.
Really it's not that I'll have to store a datetime as a string or going that low.
I just wanted to hear from people who faced a similar situation and might have some smooth magical method...
如何将它们全部保存为用户浏览器中的字符串形式的 cookie(字符串不需要在客户端进行验证,除非您将其绑定到)。只需为您的数据库提交使用服务器验证。
在此处查看有关将数据保存到 cookie 中的更多信息:
Storing multiple values in cookies
如我所说在您的模型中不使用客户端验证。
为此,只需使用 ViewModel 并将 ViewModel 保存在 Cookie 中。然后在您的控制器上,当用户想要最终保存到数据库中时验证它们。
我想我只是要在模型中进行非常无干扰的验证(即 MaxLength 等),以及一个 属性 来确定是否应该在没有验证的情况下保存模型,然后实现 IValidatableObject
我将实现所有必需的验证属性作为自定义自定义验证。
We need to create a program that collects runsheets and other form data.
All the forms need to be saved as they're typed, unless explicitly discarded, even the form field data is invalid.
The user should always be able to 'Save for later', or just shut off his window, and data should be saved.
The problem is I'm gonna have to have all the runsheets indexed and searchable, including the invalid ones.
I'm looking at few options:
- Have a subclass of the same type that implements the validation (will that work?)
- Serialize the invalid records as XML and store it somewhere else until its validated and saved permanently.
- Not use validation attributes, but just custom validation (i.e. using
IValidatableObject
interface), that will bypass validation if another 属性 on the record indicates that validation should be skipped, but then I might end up with a lot of data in the database in the same table, maybe this is not a problem as long as I'm control. I'm really considering this option the most.
My real doubt is:
- If I store data elsewhere, searching will be a nightmare
- If I make the validation in an external runtime method, avoiding the use of validation attributes, the columns in the database won't reflect the real 属性 requirements (i.e. required fields).
I think I'll go for this option, because having to search two tables bothers me more, and also because indeed the columns won't be so strict, but I can still set their MaxLength
and some other vital properties that are vital for the database structure but do not really disturb the validation process.
Really it's not that I'll have to store a datetime as a string or going that low.
I just wanted to hear from people who faced a similar situation and might have some smooth magical method...
如何将它们全部保存为用户浏览器中的字符串形式的 cookie(字符串不需要在客户端进行验证,除非您将其绑定到)。只需为您的数据库提交使用服务器验证。
在此处查看有关将数据保存到 cookie 中的更多信息:
Storing multiple values in cookies
如我所说在您的模型中不使用客户端验证。
为此,只需使用 ViewModel 并将 ViewModel 保存在 Cookie 中。然后在您的控制器上,当用户想要最终保存到数据库中时验证它们。
我想我只是要在模型中进行非常无干扰的验证(即 MaxLength 等),以及一个 属性 来确定是否应该在没有验证的情况下保存模型,然后实现 IValidatableObject
我将实现所有必需的验证属性作为自定义自定义验证。