当前位置: 移动技术网 > IT编程>开发语言>.net > MVC中通过ajax判断输入的内容是否重复(新手笔记,请各位多多指教)

MVC中通过ajax判断输入的内容是否重复(新手笔记,请各位多多指教)

2018年07月26日  | 移动技术网IT编程  | 我要评论

军嫂进化论txt,天龙八部私服xzyxtl,数独博士破解版

控制器代码:

public string ValidateCarID(string carid)
{
string result;
Car car = db.Car.Find(carid);
if(car==null)
{
result = "false"; //没有找到
}
else
{
result = "true";
}
return result;

}

 

ajax部分:

<script type="text/javascript">
$(document).ready(function () {
$("#carID").change(function () {
var caridNode = $("#carID").val();
$.ajax({
type: "post",
url: "../../Cars/ValidateCarID?carid=" + caridNode,
dataType:"text",
success: function (result) {
if (result == "true") {
$.ligerDialog.error("该车辆已注册");
}

}
});
});
});
</script>

视图控件部分:

<tr>
<td>
@Html.LabelFor(model => model.CarID, htmlAttributes: new { @class = "control-label col-md-2" })
</td>
<td>
@Html.EditorFor(model => model.CarID, new { htmlAttributes = new { @class = "form-control",id="carID"} })//这个是需要判断的控件
@Html.ValidationMessageFor(model => model.CarID, "", new { @class = "text-danger" })
</td>
</tr>

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网