Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

typeahead causing validation error asp

//In ASP.net , typeahead plugin is causing a validation error. It's cause typeahead is 
// creating a duplicate form control with the same validation properties as the original
//but leaves it empty. 

//In your view model, instead of making the property [Required], rather 
//set the required property to true in the view. 
  
//In your cshtml file
<input type="text" required placeholder="customer name" .... />
 OR
@Html.TextBoxFor( m => m.Customer.Name, new {  type="text", placeholder="customer name", required=true } )
  
 //Your model (I'm using a customer model as an example)
public class Customer {
  
    public string Name { get; set; } // make sure this is not required

    [Required]
    public string VariableThatDoesntUseTypeahead { get; set; } //you can still use [Required] if the property isn't using typeahead in the view

  	.... 
}

//You'll have to add custom validation if you don't like the default validation message "This field is required".
//You can also try to do more validation on the server instead. Unless, you create custom validation with
//JQuery validate
 
PREVIOUS NEXT
Tagged: #typeahead #causing #validation #error #asp
ADD COMMENT
Topic
Name
7+2 =