I have a class like
Public Class Task
Property DuplexType As Char
Pro开发者_运维问答perty Name As String
End Class
In my controller I have an action that looks like
<HttpPost()>
Function Edit(ByVal task As Task) As ActionResult
Dim duplexType = task.DuplexType
Dim valid = ModelState.IsValid
Return RedirectToAction("Index")
End Function
In the view, DuplexType = " " (single space) and Name = "Foo". Why doesn't the property DuplexType have a value? If I assign any other character it works fine. In the controller name = "foo" but DuplexType = " (empty).
Also ModelState.IsValid = false if DuplexType = " ".
Have a look at the Response object and examine the values being populated by the form Post. You will probably see that values are trimmed and therefore lose the space. If possible try to UrlEncode the values.
Where I have had to preserve trailing spaces in my own projects, I have ended up having to put delimiters on the parameter and then strip them off in the action method.
精彩评论