简体   繁体   中英

Verification in DropDownListFor ASP.NET

i have one element span where i can write name of courier, during the writing it's searching couriers from database. I have also one element dropDownListFor where i can chose one courier. My problem is that, when i wrote a name which not exist in my datadase i dont have any information about that. I wanted to hide submit button if the DropDownListFor is empty - the name from span is incorrect, but it doesn'twork. How can i do this?

I have partialview like this:

div class="col-md-12">
<div class="col-md-offset-4 text-center">
    <input type="text" oninput="Finder(this, '#CourierId'), check()" class="form-control"  value="@Model.CourierName" id="courier-finder" placeholder="Select courier"/>
    @Html.DropDownListFor(model => model.CourierId, (List<SelectListItem>)ViewBag.Couriers, new { @class = "form-control", onchange = "RefreshInput(this, '#courier-finder')" })
    @Html.HiddenFor(model => model.TaskId)

</div>

<script>
function check() {
    if (document.getElementById("CourierId")== "-1") {
        $("#buttonDeleteMODALAssign").hide();
    }
}

Try :

function check() {
    if ($("#CourierId").val()== "-1") {
        $("#buttonDeleteMODALAssign").hide();
    }
}

OR

function check() {
    if (document.getElementById("CourierId").value== "-1") {
       document.getElementById("buttonDeleteMODALAssign").style.display = 'none';      
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM