0

How do I specify the Value that should be entered into the Textbox. I dont want to use dropdownlist. I want to accept only these three (3) values Nigeria, Ghana and Togo

If any other value is entered it should not save or hide or disable the Save button.

View

<div class="col-md-12">
    <div>
        @Html.LabelFor(model => model.COUNTRY_NAME, "Country Name")                               
        @Html.TextBoxFor(model => model.COUNTRY_NAME, new { @style = "border-radius:3px;", @type = "text", @class = "form-control", @placeholder = "Country Name", @autocomplete = "on" })
        @Html.ValidationMessageFor(model => model.COUNTRY_NAME, null, new { @class = "text-danger" })
    </div>
</div>

Please how do I achieve this?

1
  • you can use "jquery autocomplete" to achieve this...... Commented Oct 25, 2017 at 10:34

2 Answers 2

2

There are two Options

  1. You can use Server side Custom Validator for Country_Name property.

  2. Or Jquery validation on client side.

Sign up to request clarification or add additional context in comments.

1 Comment

Please can you give a live scenario
0

When you submit the form, you can validate textbox value with jQuery.

<button onclick="validateData();"></button>

Then write a validation method as follows.

function validateData() {
    if (Nigeria, Ghana and Togo) {
        //ajax post to your controller
    } else {
        //return error message
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.