Search
 
SCRIPT & CODE EXAMPLE
 

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
Comment

PREVIOUS NEXT
Code Example
Csharp :: c# convert int to pretty string 
Csharp :: xamarin timer example 
Csharp :: c# winforms textbox readonly 
Csharp :: overload indexer c# 
Csharp :: how to get element dictionary key in c# by index 
Csharp :: shorthand in c# operator 
Csharp :: c# unity 2d play video 
Csharp :: stop sound in unity 
Csharp :: c# get binary array from int 
Csharp :: c# serviceCollection AddLogging 
Csharp :: string from byte array c# 
Csharp :: Generate UUID in c# 
Csharp :: how to destroy an object in unity 
Csharp :: unity put children in list 
Csharp :: cinemachine namespace not working 
Csharp :: blazor button onclick parameter 
Csharp :: monodevelop ubuntu 20.04 
Csharp :: .net core add header to soap request 
Csharp :: c# class to byte array 
Csharp :: west of loathing 
Csharp :: c# swap variables 
Csharp :: check distance to gameobject 
Csharp :: c# split string into characters 
Csharp :: start command line from c# 
Csharp :: get connectionstring from web config c# 
Csharp :: singleton unity 
Csharp :: how to move towards an object unity 
Csharp :: print array in c# 
Csharp :: list of string to string c# 
Csharp :: c# get value from textbox 
ADD CONTENT
Topic
Content
Source link
Name
9+4 =