Hi AliYilmaz,
Use jQuery on change event.
Refer below example.
Model
public class SubCustomers
{
public string Code { get; set; }
public string PublicTitle { get; set; }
public string AddressDetail { get; set; }
}
Controller
public class HomeController : Controller
{
public IActionResult Index()
{
List<SubCustomers> customers = new List<SubCustomers>();
customers.Add(new SubCustomers { Code = "20201272.1", PublicTitle = "V.O.F.de Vries-Dijkstra", AddressDetail = "Dijkstraat 21" });
customers.Add(new SubCustomers { Code = "20201272", PublicTitle = "V.O.F.de Vries-Dijkstra", AddressDetail = "Dijkstraat 21" });
return View(customers);
}
}
View
@model List<Select_Option_MVC_Core.Models.SubCustomers>
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<h4>SubCustomers</h4>
<select id="ddlOptions" class="js-example-basic-single" name="state">
<option value="">select</option>
@foreach (var item2 in Model)
{
<option asp-controller="Home" asp-action="CustomerBranch" asp-route-Code="@item2.Code" asp-route-returnUrl="~%2FSaleSeason">
@item2.Code / @item2.PublicTitle/ @item2.AddressDetail
</option>
}
</select>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$('#ddlOptions').on('change', function () {
var controller = $(this).find('option:selected').attr('asp-controller');
var action = $(this).find('option:selected').attr('asp-action');
var code = $(this).find('option:selected').attr('asp-route-Code');
var returnUrl = $(this).find('option:selected').attr('asp-route-returnUrl');
location.href = controller + "/" + action + "?Code=" + code + "&returnUrl=" + returnUrl;
});
});
</script>
</body>
</html>