我正在尝试验证用户是否在mvc下拉列表中选择了项目。我正在检查jquery,但有时项目被选中,但验证错误。 这是我的代码:
查看:
@Html.DropDownList("RelationType", new List<SelectListItem>()
{
new SelectListItem() { Text="partnered with", Value="1"},
new SelectListItem() { Text ="managed by", Value="2"},
new SelectListItem () { Text ="managed", Value="3"},
new SelectListItem() { Text ="referred by", Value="4"},
new SelectListItem () { Text ="referred", Value="5"}
}, "-Select Relation-", new { @class = "form-control", id = "ddlType" })
使用Javascript:
function SaveRelation(relId) {
var candidateIdd=@candidateId;
var btnText=$('#btnSaveRelation').text().trim();
if(!($('#ddlType').val()))
{
$.alert("Please select relation type", {
title: "Relation",
type: "danger"
});
return false;
}
这是我点击按钮
<button id="btnSaveRelation" type="button" class="btn c_B_Btn_L" data-toggle="modal" value="1" onclick="SaveRelation('0')">
<i class="fa fa-floppy-o" aria-hidden="true"></i>
Add
</button>
为什么有时我的验证码会出错?