Hi AliYilmaz,
Check this example. Now please take its reference and correct your code.
Database
For this example I have used of Northwind database that you can download using the link given below.
Download Northwind Database
Controller
public class HomeController : Controller
{
// GET: /Home/
public ActionResult Index()
{
NorthwindEntities eba = new NorthwindEntities();
var slider = from v in eba.Customers.Take(10)
select v;
return View(slider);
}
[HttpPost]
public ActionResult GetAll(string yaz)
{
string[] countries = yaz.Split(',');
NorthwindEntities eba = new NorthwindEntities();
var slider = from v in eba.Customers
.Where(c => countries.Contains(c.Country))
.Take(10)
.OrderBy(c => c.Country)
select v;
return View("Index", slider);
}
}
View
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<IEnumerable<_Select2_Multiselect_DropDownList.Customer>>" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Index</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css" />
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js"></script>
<script type="text/javascript">
$(function () {
$("#cos").select2({ placeholder: "Select", allowClear: false, width: "200" });
$('#cos').on('change', function (e) {
$('#yaz').val($(this).val());
});
});
</script>
</head>
<body>
<%using (Html.BeginForm("GetAll", "Home", FormMethod.Post)) { %>
<select id="cos" name="alma[]" multiple="multiple">
<option value="Argentina">Argentina</option>
<option value="Austria">Austria</option>
<option value="Belgium">Belgium</option>
<option value="Brazil">Brazil</option>
</select>
<input id="yaz" name="yaz" type="text" />
<button type="submit" class="btn btn-info">
Al</button>
<%} %>
<br />
<table class="table table-responsive">
<tr>
<th>ID</th>
<th>Name</th>
<th>City</th>
<th>Country</th>
</tr>
<% foreach (var customer in Model) {%>
<tr>
<td><%=customer.CustomerID%></td>
<td><%=customer.ContactName%></td>
<td><%=customer.City%></td>
<td><%=customer.Country%></td>
</tr>
<% }%>
</table>
</body>
</html>
Screenshot