What could be causing the dropdownlist value not to be selected or checked while using "Select2.js"?

1-Description

I have implemented a select2 filter for a dropdown list in my project.

(Tools used: Bootstrap 5 & .Net 7.0 Core)

When I choose a client name and click submit, an error occurs stating that the 'clientId' is null (indicating no client id has been selected).

2-Inquiry

What could be the issue with this code?

3-Full Code

            <div class="col-md-12">
            <!-- Modal -->
            <div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-labelledby="addModalLabel" aria-hidden="true">
                <div class="modal-dialog" role="document" style="max-width:500px;position:relative;">
                    <div class="modal-content">
                        <form id="Create" method="post" asp-page-handler="Create">
                            <div class="modal-body">
                                <div asp-validation-summary="ModelOnly" class="text-danger"></div>

                                <div class="form-group p-0">
                                    <label asp-for="Presentation.PreDate" class="border-0 m-0" style="max-height:20px;font-size:70%;">Date</label>
                                    <input asp-for="Presentation.PreDate" class="form-control font-weight-bold fw-bold text-primary" style="font-size:80%;"
                                           id="predate" type="text" readonly />
                                    <span asp-validation-for="Presentation.PreDate" class="text-danger"></span>
                                </div>                                   
                                <div class="form-group p-0">
                                     <label asp-for="Presentation.NdeId" class="border-0 m-0" style="max-height:20px;font-size:70%;">Client</label>
                                            <br>
                                            <select asp-for="Presentation.KliId" class="form-control text-primary font-weight-bold fw-bold form-select client" name="client" asp-items="ViewBag.KliId"
                                                    data-placeholder="--- Client ---" id="client" style="font-size:80%;">   
                                            </select>
                                </div>
                                <partial name="_BtnSavePopupPartial" />
                            </div>
                         </div>
                    </div>
                 </div>
            </div>
         </div>

Javascript Section

     <script type="text/javascript">
    $('.client').select2({
         width: '100%', 
        dropdownParent: $('#addModal')
    
</script>

Answer №1

Utilizing,

name="client"

Hence, you must retrieve the value from the request as client instead of clientId.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

After successfully posting a tweet, I have not heard back from Twitter

My objective is to achieve the following on click: Share the URL and text on Twitter in a popup window Receive a response from Twitter indicating whether the tweet was successful or failed Close the popup window after the tweet is successfully pos ...

Acquiring the console log data from Firefox version 43 using Selenium, all without the use of any

Can Selenium retrieve the console.log from browsers like Firefox 43? If so, how can it be done? My settings are as follows: DesiredCapabilities capabilities = DesiredCapabilities.firefox(); LoggingPreferences logs = new LoggingPreferences(); logs.enable( ...

Randomly generated numerical value in input field

How can I generate a 15-digit number using JS code and then reduce it to just 5 or 6 digits in a text box? <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script type="text/javascript ...

What is the process for incorporating the !important declaration into a CSS-in-JS (JSS) class attribute?

I'm currently exploring the use of CSS-in-JS classes from this specific response in conjunction with a Material UI component within my React project. In order to override the CSS set by Bootstrap, I've decided to utilize the !important modifier. ...

Implement a dynamic loading feature using AJAX, pushState, and Jekyll for a

In an effort to create a standard template for our studio's Jekyll sites development, I am aiming to implement page animation transitions. My plan involves loading different content from each page using AJAX and utilizing pushState to update the URL a ...

Center-align the table element

I've been struggling to center align this table element, specifically the one containing the square, but nothing seems to be working. Can anyone lend a hand in fixing this issue? <table> <tbody> <tr> <td>TURKEY - SU ...

Is a missing dependency causing an issue with the React Hook useEffect?

I've encountered an issue with the following code snippet, which seems to only depend on [page]. Despite this, I am receiving the error message: React Hook useEffect has a missing dependency I've come across similar discussions suggesting to com ...

ajax encountering error but producing correct result

Below is the code snippet for a function: side= 'car'; var request_checkUrl = '/antibot/antibot_data?script=' + side; $.ajax({ url: request_checkUrl, dataType: 'application/json', complete: function(data){ ...

I am interested in incorporating the ability to select and scroll the window without needing to interact with the scroll bar by

Imagine a visitor wanting to highlight all the information on a webpage. They choose to start dragging their cursor towards the bottom of the window. How can we enable the webpage to smoothly scroll down as they do this? ...

Can an infowindow be automatically closed based on specific criteria?

Show the infowindow only when hovering over the marker. It should disappear when moving the mouse away from the marker. The infowindow should stay open only if you click on the marker, and can be closed by clicking the close button on the infowindow. ...

Trigger a series of child functions upon clicking the parent button

I am facing an issue where I am attempting to trigger the functions of each child component from a button click event on the parent component. I have tried using props and setting up a new function in the componentDidMount lifecycle method, but only the la ...

Tips for customizing bootstrap code for registration form to validate against duplicate emails?

The contact_me form utilizes default code to handle success or failure responses from the server. The code calls msend_form.php for communication with the database and always returns true. It allows checking for pre-existing email addresses in the database ...

Personalized dropdown appearance

During my work on a select box, I discovered that custom styling is not possible. I attempted to use some plugins but did not find one that met my needs. I am seeking a dropdown menu with options in both black and gray, similar to this template but using ...

"Internet Explorer naturally selects the submit button when users press the enter key to submit a

In my current application, I have implemented a form with a hidden button to address issues with the numeric keyboard on Android. Essentially, pressing enter or focusing on the invisible button will trigger form submission. Pressing enter works fine in Ch ...

Combining array values in Node.js/JavaScript by matching key values

Looking to merge two arrays by matching key values in JavaScript/Node.js. Check out the code snippet below: var userData=[{'email':'<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d8b998bfb5b9b1b4f6bbb7b5">[em ...

Having trouble with submitting the code - need help resolving the issue

I'm facing an issue with my submit cancel code. The JavaScript code I implemented for preventing the submission function on my page isn't working as expected. While it does work to a certain extent, it's not fully functional. I am seeking a ...

Exploring the process of implementing smooth transitions when toggling between light and dark modes using JavaScript

var container = document.querySelector(".container") var light2 = document.getElementById("light"); var dark2 = document.getElementById("dark"); light2.addEventListener('click', lightMode); function lightMode(){ contai ...

Generate several invoices with just a single click using TypeScript

I'm interested in efficiently printing multiple custom HTML invoices with just one click, similar to this example: https://i.sstatic.net/hAQgv.png Although I attempted to achieve this functionality using the following method, it appears to be incorr ...

What is the best way to instruct Maven to package my JavaScript project as a war file from the root directory?

Hey everyone, I'm still searching for a reliable method to package a javascript project. Typically, the default approach is to simply release it to the docroot of your appserver, which I find quite unpleasant. My simple node.js javascript project, w ...

Displaying content in a hidden div on click event

I am part of a volunteer group for prostate cancer awareness and support, and our website features multiple YouTube videos that are embedded. However, the page has been experiencing slow loading times due to the number of videos, despite them being hidden ...