从模态使用远程验证
Use remote validation from a modal
Remote 验证在模式中不起作用。
模态和ajax方法来自本教程:
codaffection.com/how-to-use-jquery-ajax-in-asp-net-core-mvc-for-crud-operations-with-modal-popup/
视图模型:
[Required]
[Remote(action: "VerifyVIN",controller: "Dashboard")]
public string VIN { get; set; }
DashboardController.cs :
[AcceptVerbs("Get","Post")]
public async Task<IActionResult> VerifyVIN(string VIN)
{
if (!string.IsNullOrEmpty(VIN))
{
var result = await _inventoryService.VerifyVIN(VIN);
return Json(result ? "true" : string.Format("a car for VIN : {0} already exists.",VIN));
}
return Json("false");
}
邮递员为 :
提供代码 200
Dashboard/VerifyVIN?VIN=1FUJAPCK25DU88948 (string.Format)
Dashboard/VerifyVIN?VIN=测试(“真”)
Dashboard/VerifyVIN(“假”)
当然在普通页面内一切正常。 (例如:https://localhost:5001/Dashboard/Index1)
感谢阅读。
礼貌可以吗?
site.js
verifyVIN = url => {
var VIN = document.getElementById("VIN").value;
url = url + "?VIN=" + VIN
$.ajax({
type: "POST",
url: url,
success: function (res) {
},
error: function (err) {
console.log(err)
}
})
}
View.cshtml
<input onchange="verifyVIN('@Url.Action("VerifyVIN","Dashboard",null,Context.Request.Scheme)')" asp-for="VIN" class="form-control" />
Remote 验证在模式中不起作用。
模态和ajax方法来自本教程:
codaffection.com/how-to-use-jquery-ajax-in-asp-net-core-mvc-for-crud-operations-with-modal-popup/
视图模型:
[Required]
[Remote(action: "VerifyVIN",controller: "Dashboard")]
public string VIN { get; set; }
DashboardController.cs :
[AcceptVerbs("Get","Post")]
public async Task<IActionResult> VerifyVIN(string VIN)
{
if (!string.IsNullOrEmpty(VIN))
{
var result = await _inventoryService.VerifyVIN(VIN);
return Json(result ? "true" : string.Format("a car for VIN : {0} already exists.",VIN));
}
return Json("false");
}
邮递员为 :
提供代码 200
Dashboard/VerifyVIN?VIN=1FUJAPCK25DU88948 (string.Format)
Dashboard/VerifyVIN?VIN=测试(“真”)
Dashboard/VerifyVIN(“假”)
当然在普通页面内一切正常。 (例如:https://localhost:5001/Dashboard/Index1)
感谢阅读。
礼貌可以吗?
site.js
verifyVIN = url => {
var VIN = document.getElementById("VIN").value;
url = url + "?VIN=" + VIN
$.ajax({
type: "POST",
url: url,
success: function (res) {
},
error: function (err) {
console.log(err)
}
})
}
View.cshtml
<input onchange="verifyVIN('@Url.Action("VerifyVIN","Dashboard",null,Context.Request.Scheme)')" asp-for="VIN" class="form-control" />