Hi nabilabolo,
Check this example. Now please take its reference and correct your code.
Model
public class Customer
{
public int code { get; set; }
public List<SelectListItem> DropdownSpecial { get; set; }
}
Controller
public class HomeController : Controller
{
// GET: Home
public ActionResult Index()
{
Customer customer = new Customer();
customer.DropdownSpecial = new List<SelectListItem>()
{
new SelectListItem{ Text="Item 1", Value="1" },
new SelectListItem{ Text="Item 2", Value="2" },
new SelectListItem{ Text="Item 3", Value="3" },
new SelectListItem{ Text="Item 4", Value="4" },
new SelectListItem{ Text="Item 5", Value="5" },
new SelectListItem{ Text="Item 6", Value="6" },
new SelectListItem{ Text="Item 7", Value="7" }
};
return View(customer);
}
}
View
@model Validation_DropDownList_Row_MVC.Models.Customer
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
var selected = [];
$('[id$=ddlDropdownProductType]').change(function () {
if (selected.indexOf($(this).val()) == -1) {
selected.push($(this).val());
} else {
alert('Item already selected.');
$(this).val('');
}
});
});
</script>
</head>
<body>
@for (int i = 1; i <= 7; i++)
{
<div class="col-md-5" style="width:100%;">
@i.
@Html.DropDownListFor(a => a.code, Model.DropdownSpecial, "Select", new { @id = "ddlDropdownProductType" })
</div>
<br />
}
</body>
</html>
Screenshot