[cshtml]
<form id="dropdownsform" method="post">
<div class="form-group">
<div>
<ejs-dropdownlist id="DropTitle" ejs-for="DropTitle" dataSource="@ViewBag.data" placeholder="Select a game" popupHeight="220px">
</ejs-dropdownlist>
<span asp-validation-for="DropTitle" class="text-danger"></span>
</div>
</div>
<input type="submit" value="submit" class="e-control e-btn"/>
</form>
[cs]
public IActionResult Index()
{
ViewBag.data = new string[] { "Badminton", "Basketball", "Cricket", "Football", "Golf", "Gymnastics", "Hockey", "Tennis" };
return View();
}
public class Annotation
{
[Required(ErrorMessage = "DropDownList value is required")]
public string DropTitle { get; set; }
}
|
public IActionResult PostExample(Annotation annotation)
{
if (!ModelState.IsValid)
{
ViewBag.data = new List<Test> { new Test { Id = 1, Name = "Name-1" }, new Test { Id = 2, Name = "Name-2" } };
return View("index");
}
return View("index");
} |