Asp.net mvc 为什么DefaultModelBinder不绑定到值为“c”的Char属性

Asp.net mvc 为什么DefaultModelBinder不绑定到值为“c”的Char属性,asp.net-mvc,model-binding,Asp.net Mvc,Model Binding,我有一门课 Public Class Task Property DuplexType As Char Property Name As String End Class 在我的控制器中,我有一个动作 <HttpPost()> Function Edit(ByVal task As Task) As ActionResult Dim duplexType = task.DuplexType Dim valid = ModelState.IsValid

我有一门课

Public Class Task
    Property DuplexType As Char
    Property Name As String
End Class
在我的控制器中,我有一个动作

<HttpPost()>
Function Edit(ByVal task As Task) As ActionResult
    Dim duplexType = task.DuplexType
    Dim valid = ModelState.IsValid
    Return RedirectToAction("Index")
End Function
在视图中,DuplexType=singlespace,Name=Foo。为什么属性DuplexType没有值?如果我指定任何其他字符,它工作正常。 在控制器中,name=foo,但DuplexType=empty


如果DuplexType=,则ModelState.IsValid=false

查看响应对象并检查表单Post填充的值。您可能会看到值被修剪,因此会丢失空间。如果可能,尝试对值进行URL编码


在我自己的项目中,我不得不保留尾随空格,最后我不得不在参数上放置分隔符,然后在action方法中去掉它们。

当我查看HttpContext.Request.Form.ItemDuplexType时,它是正确的,但task对象没有得到值和ModelState.IsValid=false