views:

19

answers:

1

I have a class like

Public Class Task
    Property DuplexType As Char
    Property 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 = " ".

A: 

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.

Clicktricity
When I look at HttpContext.Request.Form.Item("DuplexType") it is " " which is correct but the task object does not get the value and the ModelState.IsValid = false
t-boy