帐户模型类别:
[Table("Accounts")]
public class Account
{
public int Id { get; set; }
public string CompanyName { get; set; }
public float Interval { get; set; }
}
移动模型类:
public class Mobile
{
public int Id { get; set; }
public string MobileNo { get; set; }
public virtual Account Account { get; set; }
public static Mobile Add(string mobile)
{
Mobile mobiles = new Mobile();
mobiles.MobileNo = mobile;
return mobiles;
}
}
查看:
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group row">
@Html.LabelFor(model => model.Name, htmlAttributes: new { @class = "col-sm-2 col-md-1 col-form-label" })
<div class="col-sm-10 col-md-3">
@Html.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group row">
@Html.LabelFor(model => model.Interval, htmlAttributes: new { @class = "col-sm-2 col-md-1 col-form-label" })
<div class="col-sm-10 col-md-3">
@Html.EditorFor(model => model.Interval, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Interval, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group row">
@Html.LabelFor(model => model.Mobile, htmlAttributes: new { @class = "col-sm-2 col-md-1 col-form-label" })
<div class="col-sm-10 col-md-3">
<span class="add-new-icon glyphicon glyphicon-plus-sign" id="add_mobile"> </span>
<input name="Mobile" class="form-control" id="mobile_no" />
</div>
</div>
<div class="form-group row">
@Html.LabelFor(model => model.Mobile, htmlAttributes: new { @class = "col-sm-2 col-md-1 col-form-label" })
<div class="col-sm-10 col-md-3">
<span class="add-new-icon glyphicon glyphicon-plus-sign" id="add_mobile"> </span>
<input name="Mobile" class="form-control" />
</div>
</div>
<div class="form-group row">
@Html.LabelFor(model => model.Mobile, htmlAttributes: new { @class = "col-sm-2 col-md-1 col-form-label" })
<div class="col-sm-10 col-md-3">
<span class="add-new-icon glyphicon glyphicon-plus-sign" id="add_mobile"> </span>
<input name="Mobile" class="form-control" />
</div>
</div>
在这里,我为 移动 输入了3个输入字段。我可以为 名称 或 时间间隔 添加验证规则。但是如何为 移动 添加验证规则。即:我想检查手机号码的唯一性,并且前两个输入字段包含唯一的手机号码,其中第二个输入字段包含重复的手机号码。因此,对于第三个输入字段的验证失败。有想法吗?