Friday, 15 February 2013

c# - ASP.NET MVC 5 TryUpdateModel not allowing & in string -



c# - ASP.NET MVC 5 TryUpdateModel not allowing & in string -

starting original string of: "text=ab&c", value passed through httputility.parsequerystring create namevaluecollection.

then create ivalueprovider tryupdatemodel, namevaluecollection creates new namevaluecollectionprodvier.

at point in namevaluecollectionvalueprovider, key becomes text , value still remains ab&c.

when tryupdatemodel called passing in values, text changes ab&c ab.

any thoughts on why might be?

here code:

e foreach passed in controller actionresult model value

foreach (string e in model.elements) { string querystring = httputility.urldecode(e); var model = new model(); namevaluecollection namevalues = httputility.parsequerystring(querystring); // namevalues = {text=ab&c} @ point var provider = new namevaluecollectionvalueprovider(namevalues, system.globalization.cultureinfo.currentuiculture); // provider = namevaluecollectionvalueprovider @ point // it's _values has count=1 // @ index [0] has value {[text, system.web.mvc.namevaluecollectionprovider+valueproviderresultplaceholder]} // has key of "text" // , value of system.web.mvc.namevaluecollectionprovider // within value, it's broken downwards properties // system.web.mvc.namevaluecollectionprovider // _validatedcollection , _unvalidatedcollection both have value of text=ab&c // see validatedresult , unvalidatedresult both have value of ab tryupdatemodel(model, provider);

the model's text value declared public string text { get; set; } tryupdatemodel find matching text declaration.

updated:

i found within namevaluecollectionvalueprovider, provider's value has _unvalidatedcollection , _validatedcollection expected result of text=ab&c unvalidatedresult , validatedresult within provider both have value of ab.

it seems provider removing values after &.

can provider farther encoded maintain & in string?

you need encode when building url , decode when trying read url params string querystring = "text=" + httputility.urlencode("ab&c");

c# asp.net asp.net-mvc

No comments:

Post a Comment