asp.net mvc 5 - MVC 5 trouble on validating posted form inputs that are html encoded -


i have view model string property:

    [stringlength(10)]     public string phone { get; set; } 

in view:

@html.editorfor(x => x.phone) 

if enter '+12' , submit, 'phone' html encoded , controller gets enter image description here , had decode before saving database:

httputility.htmldecode(phone); 

is normal behavior?

another problem entering '+123456789' fails string length checks because encoded.

how handle this?

edit:

my controller action looks like:

    [httppost]     [validateantiforgerytoken]     public actionresult edit([bind(include = "phone")] myviewmodel vm) 

edit2:

i using custom template default adding sanitizing module modelbinders in application_start() causing trouble. garryp pointed out, framework takes care of once rid of custom binder , controller getting exact string user entered. not encoding/decodings happening on entered string though..

it shouldn't necessary htmldecode value; framework should take care of this. store un-encoded values in database , encode them on ui (to prevent xss attacks , like).

i check following:

  1. are allowing framework resolve model you? ie actions have model in signature or using request.form, or similar mechanism?
  2. have encoded value twice? decoded once when comes server.
  3. how passing values server? passing load of string flags in controller action?

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -