ASP.NETMVC3とEF4.1を使用しています。モデルに2つのDropDownListがあります。これは必須であり、複製もされていません。そして、リモート検証関数が必要です。ユーザーがデータを送信すると、ValidateDuplicateInsertが起動します。しかし、ValidateDuplicateInsert関数を起動できません。私はどこが間違っていますか?
私のモデル
[Key]
public int CMAndOrgID { get; set; }
[Display(Name = "CM")]
[Required(ErrorMessage = "CM is required.")]
[Remote("ValidateDuplicateInsert", "CMAndOrg", HttpMethod = "Post", AdditionalFields = "CMID, OrganizationID", ErrorMessage = "CM is assigned to this Organization.")]
public int? CMID { get; set; }
[Display(Name = "Organization")]
[Required(ErrorMessage = "Organization is required.")]
public int? OrganizationID { get; set; }
public virtual CM CM { get; set; }
public virtual Organization Organization { get; set; }
CMAndOrgコントローラーのValidateDuplicateInsert関数
[HttpPost]
public ActionResult ValidateDuplicateInsert(string cmID, string orgID)
{
bool flagResult = true;
foreach (CMAndOrg item in db.CMAndOrgs)
{
if (item.CMID.ToString() == cmID && item.OrganizationID.ToString() == orgID)
{
flagResult = false;
break;
}
}
return Json(flagResult);
}
そして私の見解
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>CMAndOrg</legend>
<div class="editor-label">
@Html.LabelFor(model => model.CMID, "CM")
</div>
<div class="editor-field">
@Html.DropDownList("CMID", String.Empty)
@Html.ValidationMessageFor(model => model.CMID)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.OrganizationID, "Organization")
</div>
<div class="editor-field">
@Html.DropDownList("OrganizationID", String.Empty)
@Html.ValidationMessageFor(model => model.OrganizationID)
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}