我得到以下InvalidOperationException異常:MVC2:不能將字符串轉換爲ExtensionDataObject(不知道我想)
The parameter conversion from type 'System.String' to type 'System.Runtime.Serialization.ExtensionDataObject' failed because no type converter can convert between these types.
在我的ASP.Net MVC2頁面上張貼的動作,但我真的不知道它指的是什麼。我使用的數據註釋驗證:
public class FamilyPersonMetadata
{
[Required(ErrorMessage = "Name Required")]
public String Name;
[Required(ErrorMessage = "Date of Birth required")]
[DateTime(ErrorMessage = "Invalid Date")]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:d")]
public DateTime DateOfBirth;
}
[MetadataType(typeof(FamilyPersonMetadata))]
public partial class FamilyPerson
{
}
而從用的ViewPage的FamilyPerson亞型我的觀點inhertis。我只是使用與FamilyPerson相匹配的名稱創建控件,然後提交表單,但由於某種原因,我的ModelState無效,上述錯誤顯然是原因。對於錯誤的性質我很困惑。類似的代碼適用於其他視圖和操作。
有人能指點我的事情的方向看,可能會導致這種情況嗎?
如果您註釋掉MetadataType屬性,會發生什麼情況?一切正常嗎?嘗試並消除此問題中的某些變量將會有所幫助。 – Eilon 2010-01-09 21:07:54