asp.net MVC3: Trimming all HTTP POST data
I need to do trim to all HTTP POST data submitted by users through web forms. Having done googling, apparently there is no in-built functionality in asp.net to trim all HTTP POST data.
The closest that I can get is what is described here: ASP.NET MVC: Best way to trim strings after data entry. Should I create a custom model binder?
Unfortunately it doesn't work on nested ViewModels (ViewModel with property with type of other ViewModel).
What is the best way to achieve this? I don't wa开发者_JAVA百科nt to do property.Trim() on every properties in all ViewModel. Thank you.
One option is to define your own IValueProvider
. I would start by inheriting from NameValueCollectionValueProvider
to make a TrimmedNameValueCollectionValueProvider
in which you trim the results as you pull them out. Then you would defined a TrimmedFormValueProvider
that passes in controllerContext.HttpContext.Request.Form
as the collection
.
精彩评论