I have an Action that receives a class with a dictionary in its properties:
public ActionResult TestAction(TestClass testClass)
{
return View();
}
public class TestClass
{
public Dictionary<string, string> KeyValues { get; set; }
}
If I do a post to my action with the following JSON:
{
"KeyValues": {
"test.withDoT": "testWithDot"
}
}
The key in my dictionary is stripped to the dot and has nothing in the value.
Trying without the dot works. How can I do a post with a dot in a Dictionary<string, string>
with MVC?
We gave a blind try supposing that there is a regex parser somewhere in the deep (well it was minimal the chance) and to escape 'dot'.
After thinking a while I concluded: dot is not a legal char in identifiers. Yes I know it is a key in the C# dictionary, but in the json part (and javascript) it could be in the identifier syntax role.
So I strongly suggest to replace client side the .
(dot) with an escape sequence like _dot_
and replace back it in server side. Performance will suffer of course.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With