我试图检查TerminalID是否已被其他型号占用。 Ajax正确回发并且也可以看到错误消息,但页面不允许我提交,我只需要在输入时检查此信息以显示错误消息然后发布。请帮帮我
型号:
public class MoveModel
{
[Required]
[Remote("CheckExistTrm", "MoveModel")]
public int TerminalID { get; set; }
public string User { get; set; }
........
}
控制器:
public JsonResult CheckExistTrm(int TerminalID)
{
var terminal = db.Terminals.Find(TerminalID);
if (terminal == null)
return null;
var agrdet = (from t in db.AgreementDetails where (t.TerminalID == terminal.TerminalID && t.Condition == "New") select t).FirstOrDefault();
if (agrdet != null)
{
var agreement = db.Agreements.Find(agrdet.AgreementID);
return Json("consider! this terminal is active in the agreement: " + agreement.AgreementNumber ,JsonRequestBehavior.AllowGet);
}
else
{
return Json(true, JsonRequestBehavior.AllowGet);
}
}
查看(我正在使用devexpress):
@using (Html.BeginForm("CreateAndEdit", "MoveModel", FormMethod.Post, new { @class = "edit_form" })){
@Html.AntiForgeryToken()
@Html.Hidden("MoveModelID")
<div class="line">
@Html.DevExpress().Label(
settings =>
{
settings.ControlStyle.CssClass = "label";
settings.AssociatedControlName = "TerminalID";
settings.Text = "ტემრინალი";
}
).GetHtml()
@Html.DevExpress().ComboBox(
settings =>
{
settings.Name = "TerminalID";
settings.ControlStyle.CssClass = "editor";
settings.Properties.TextField = "Name";
settings.Properties.ValueField = "TerminalID";
settings.Properties.ValueType = typeof(int);
settings.Properties.DropDownStyle = DropDownStyle.DropDown;
settings.Properties.IncrementalFilteringMode = IncrementalFilteringMode.Contains;
}
).BindList(LeaseReg.Models.Terminal.getTerminals()).Bind(Model.TerminalID).GetHtml()
@Html.ValidationMessageFor(model => model.TerminalID,null, new { @class = "validator" })
</div>
<div class="line">
@Html.DevExpress().Label(
settings =>
{
settings.ControlStyle.CssClass = "label";
}
).GetHtml()
@Html.DevExpress().Button(
settings =>
{
settings.Name = "btnUpdate";
settings.ControlStyle.CssClass = "button";
settings.Text = "დადასტურება";
settings.UseSubmitBehavior = true;
}
).GetHtml()
@Html.DevExpress().Button(
settings =>
{
settings.Name = "btnCancel";
settings.ControlStyle.CssClass = "button"; ;
settings.Text = "გაუქმება";
settings.ClientSideEvents.Click = "function(s, e){ document.location='" + DevExpressHelper.GetUrl(new { Controller = "MoveModel", Action = "Index" }) + "'; }";
}
).GetHtml()
</div>
@Html.ValidationSummary(true);}