我有一個應用程序利用EntityFramework與SQL2008。我使用DB優先方法。下面顯示兩個實體我有問題:員工Edit.cshtml在ASP.NET MVC3編輯和驗證複雜模型
<div class="client_row">
<label class="client_label">
FirstName</label>
@Html.TextBoxFor(model => model.FirstName, new { @class = "client_edit" })
@Html.ValidationMessageFor(model => model.FirstName)
</div>
<div class="client_row">
<label class="client_label">
LastName</label>
@Html.TextBoxFor(model => model.LastName, new { @class = "client_edit" })
@Html.ValidationMessageFor(model => model.LastName)
</div>
@Html.EditorFor(model => model.Account)
<div class="client_row">
<span class="client_hr"></span>
<label class="client_label">
Email</label>
@Html.TextBoxFor(model => model.Email, new { @class = "client_edit" })
@Html.ValidationMessageFor(model => model.Email)
</div>
賬戶編輯文件的
http://imageshack.us/photo/my-images/339/modelfj.jpg/
部分(由EditorFor用戶)
@Html.HiddenFor(model => model.AccountID)
<div class="client_row">
<label class="client_label">
Login</label>
@Html.TextBoxFor(model => model.Login, new { @class = "client_edit" })
@Html.ValidationMessageFor(model => model.Login)
</div>
<div class="client_row">
<label class="client_label">
Password</label>
@Html.PasswordFor(model => model.Password, new { @class = "client_edit password1" })
我的部分帳戶文件SED進行驗證
[MetadataType(typeof(Account_Validation))]
public partial class Account
{
}
[Bind(Exclude = "AccountID")]
public class Account_Validation
{
[Required]
[Remote("IsLoginAvailable", "Validation")]
[Display(Name="Login")]
public string Login { get; set; }
[DataType(DataType.Password)]
[Display(Name="Password")]
public string Password { get; set; }
}
@Html.ValidationMessageFor(model => model.Password)
</div>
當我試圖創建一個僱員一切工作正常。我可以插入Employee表和Account表。我已經實現了標準的遠程驗證(使用數據註釋)來檢查登錄名的可用性。
問題在我試圖編輯員工時開始。驗證不會允許我這樣做,就像它說的登錄已被佔用一樣。那麼,這是真的,但我不想改變它。你們能告訴我我做錯了什麼嗎?
您能否提供您的模型上現有DataAnnotations的示例? –
當然,我只是添加了代碼示例 – torm