We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Dropdownlist - Unobstrusive validation

Hi support,

I'm trying to use unobstrusive validation (model annotation) with dropdownlist, but it's not working.
Everything works with textbox.

How can I configure validation for dropdownlist controls?

Regards

7 Replies

DL Deepa Loganathan Syncfusion Team January 16, 2019 12:41 PM UTC

Hi Daniel,  
 
Thanks for contacting Syncfusion support. 
 
We have created a simple test sample to test the unobtrusive validation of Dropdownlist with Data annotation and we can confirm that the Dropdownlist is rendering properly without any issues. Please find the below code sample. 
 
[cshtml] 
 
<form id="dropdownsform" method="post"> 
    <div class="form-group"> 
        <div> 
            <ejs-dropdownlist id="DropTitle" ejs-for="DropTitle" dataSource="@ViewBag.data" placeholder="Select a game" popupHeight="220px"> 
            </ejs-dropdownlist> 
            <span asp-validation-for="DropTitle" class="text-danger"></span> 
        </div> 
    </div> 
 
    <input type="submit" value="submit" class="e-control e-btn"/> 
</form> 
 
[cs] 
 
public IActionResult Index() 
        { 
            ViewBag.data = new string[] { "Badminton", "Basketball", "Cricket", "Football", "Golf", "Gymnastics", "Hockey", "Tennis" }; 
            return View(); 
        } 
 
public class Annotation 
    { 
        [Required(ErrorMessage = "DropDownList value is required")] 
        public string DropTitle { get; set; } 
 
} 
 
 
 
For your reference, we have attached the test sample in the below link.  
 
Sample:  
 
So, kindly check if the ID is mapped properly and if the issue still persists, get back to us with the below details.  
 
1.      Are you facing any script error? 
2.      Video of the issue 
3.      View and Model used in your application 
 
The details you provide would help us in further investigation of the issue and provide you a prompt solution at the earliest. 
 
Regards,  
Deepa L. 



DD Daniel Duvoisin January 16, 2019 07:41 PM UTC

Hi Deepa,

Thank you for the answer, but i don't see the link (for the sample).
Another question, I can't find the nugets of version 16.4, can you help me?

Regards


PO Prince Oliver Syncfusion Team January 17, 2019 10:48 AM UTC

Hi Daniel,   

Thank you for your update. 


You can find the NuGet packages for EJ2 ASP.NET Core from following package source. 

Syncfusion publishing the NuGet packages in nuget.org. Please find the Syncfusion NuGet packages v16.4 from below link.   
  
You can use the search option in Visual Studio NuGet package manager to install the required packages.   

Furthermore, Take a moment to look at the following KB document that is related to the issue: https://www.syncfusion.com/kb/9337/syncfusion-nuget-packages-updates-not-available-for-latest-version 

Please let us know if you need any further assistance on this. 

Regards, 
Prince 



DD Daniel Duvoisin January 18, 2019 09:14 PM UTC

Hi Prince,

I have created a simple project to test the unobstrustive validation and i have reproduced the problem.
Please find my sample in attachment.

Regards

Attachment: syncfusionrequired_ec6fd32f.zip


CI Christopher Issac Sunder K Syncfusion Team January 22, 2019 06:01 AM UTC

Hi Daniel, 

Thanks for the update. 

We have checked your shared sample. The cause of the problem is, you have used 16.4.0.42 version, but the data-annotation attribute in ASP.NET Core Tag helper support is provided in version 16.4.0.47. We suggest you upgrade the package to the latest version. We have updated the version in the provided sample and the validation is working fine. Please find the modified sample for your reference.  


Please check it and let us know if you have any concerns. 

Thanks, 
Christo 



JW James Welty September 12, 2019 01:29 PM UTC

This sample has a bug. The error message don't go away once we select a value


AB Ashokkumar Balasubramanian Syncfusion Team September 13, 2019 10:26 AM UTC

Hi Daniel, 
 
We would like to inform you that our Dropdown List component server-side validation will begin after the form submission. We have checked this scenario in your provided sample, it’s works properly at our end.  
 
Also, if you want the Dropdown List component with dataSource on after form submission, we need to return the corresponding dataSource in server-side. Could you please check the below block and sample? 
 
public IActionResult PostExample(Annotation annotation) 
        { 
            if (!ModelState.IsValid) 
            { 
                ViewBag.data = new List<Test> { new Test { Id = 1, Name = "Name-1" }, new Test { Id = 2, Name = "Name-2" } }; 
                return View("index"); 
            } 
 
            return View("index"); 
 
        } 
 
Sample:  
 
 
Could you please check the sample and let us know, if you require any further assistance on this? 
 
Regards, 
Ashokkumar B. 


Loader.
Up arrow icon