我有一個具有顯式屬性的模型類,它似乎MVC活頁夾不綁定它們。我得到錯誤MVC綁定顯式屬性
System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary
這是已知的問題嗎?我無法在google上找到關於此的任何文檔。
我班
public interface IPdf2Source
{
string Password { get; set; }
string OutputFormatSelected { get; set; }
}
public class OptionModel : IPdf2Source
{
public IPdf2Source Pdf2Source
{
get { return this; }
}
//Bind Ok
public string Email { get; set; }
//I get error on these properties while binding.
string IPdf2Source.Password { get; set; }
string IPdf2Source.OutputFormatSelected { get; set; }
}
查看
@using (Html.BeginForm())
{
@Html.TextBoxFor(p => p.Email)
@Html.TextBoxFor(p => p.Pdf2Source.Password)
@Html.HiddenFor(p=>p.Pdf2Source.OutputFormatSelected)
}
控制器動作,因爲綁定失敗這是永遠不會被調用。如果我刪除顯式聲明的屬性,一切工作正常。
public JsonResult ValidateFile(OptionModel formData)
{
}
顯示一些代碼。 – 2012-03-23 07:59:25
我已更新帖子。 – Tomas 2012-03-23 08:01:46
請在您的問題中顯示一些代碼,以便我們可以更好地瞭解您的問題。添加儘可能多的代碼。 – 2012-03-23 08:02:30