How to get the value of “<select></select>” from a view into a Controller's “ActionResult”?

How to get the value of “<select></select>” from a view into a Controller's “ActionResult”?

I have a tag and a button. On click of the button, an actionResult in a controller is called. Like this.

I have a tag and a button. On click of the button, an actionResult in a controller is called. Like this.

<button type="button" onclick="location.href='@Url.Action("GetAllItems", "Items")'">Get Items</button>

And here's the ActionResult

public ActionResult GetAllItems() {
        string selectedItem = string.Empty;
        ItemsRepository itemsRepository = new ItemsRepository();
        ModelState.Clear();
        return View(itemsRepository.GetAllItems());
    }

selectedItem is the variable I want to store either the selectedText or the selectedValue. But I don't know how to.

This is the <Select> tag.

<select style="width:170px" id="ItemsID" name="Items"></select>

And this is the rough function to get the different results from onChange event.

<script>
$(document).ready(function () {
    $("#ItemsID").change(function () {
        var a = $('#ItemsID option:selected').val();
        var b = $('#ItemsID option:selected').text().trim();
        var c = $('#ItemsID option:selected').index();

    alert(a);
    alert(b);
    alert(c);
})

});

Please help.

javascript c-sharp jquery asp.net

What's new in Bootstrap 5 and when Bootstrap 5 release date?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Random Password Generator Online

HTML Color Picker online | HEX Color Picker | RGB Color Picker

Jquery from validation || ASP NET Core client side validation

LIKE | COMMENT | SHARE | SUBSCRIBE In this video, I will show you how to add form validation using jquery. Subscribe & Stay Connected! Thank You! ♥ #Identity...

How to implement JWT Authentication in ASP.NET Core 3.0 API with C#

In this tutorial we'll go through a simple example of how to implement JWT (JSON Web Token) authentication in an ASP.NET Core 3.0 API with C#

ASP.NET MVC Application with JQuery, AJAX

Let's have a sample example: We have a submit button in our JQuery AJAX MVC application. Let's try to show a message when it is clicked. ASP.NET MVC Application - Using JQuery, AJAX

Add asp.net Identity in empty project

LIKE | COMMENT | SHARE | SUBSCRIBE Today, in this tutorial you will see the process of adding an ASP.NET Identity to the ASP.NET Web Application developed in...

List all users from asp net core identity

LIKE | COMMENT | SHARE | SUBSCRIBE In this video, i will show you How to retrieve and display all the registered application users in asp.net core using the ...