我需要使用bootstrap模式在ASP MVC中进行远程验证帮助。
所以,我有一个简单形式的模态。我已经包含了jquery脚本。
<form id="fModal">
<div id="modalUpload" class="modal fade uploadModal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">x</button>
<div class="modal-title align-center"><h3>Carica il tuo file</h3></div>
</div>
<div class="modal-body">
<div class="row ">
<div class="col-md-6">
@Html.DropDownListFor(m => m.SocietaId, SelectListHelper.Init(), new { @id = "SetCombo" })
</div>
<div class="col-md-4">
<input type="file" id="fUpload" name="fUpload">
</div>
</div>
</div>
<div class="modal-footer">
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.ValidationMessageFor(m => m.fUpload, "", new { @class = "text-danger" })
@Html.ValidationMessageFor(m => m.SocietaId, "", new { @class = "text-danger" })
<button class="btn btn-primary" type="submit" onclick="app.modal.upload()" name="btnUpload" id="btnUpload">
Upload
</button>
</div>
</div>
</div>
</div>
</form>
<script type="text/javascript">
$(document).ready(function () {
$.validator.unobtrusive.parse("#fModal");
});
</script>
这是我的操作员
public JsonResult CheckSocieta(SetModel model)
{
object rt = null; //variabile per messaggio personalizzato
if (model.SocietaId != 0)
{
var query = DataContext.CashFlow.FirstOrDefault(x => x.CompanyId == model.SocietaId);
if (query == null)
rt = true;
else
rt = "Società già inserita";
}
else
rt = "Selezionare una società";
return Json(rt, JsonRequestBehavior.AllowGet);
}
这是具有远程数据注释的模型
[Required, AllowHtml]
[Remote("CheckSocieta", "Set", ErrorMessage = "Selezionare una società")]
public int SocietaId { get; set; }
永远不会调用该操作,但必需的工作。 实际上,当我单击按钮时,会显示必填字段消息。
我不知道为什么行动不起作用..
你能帮帮我吗?