Click here to Skip to main content
15,075,492 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i am using MVC 3 and Razor, how to validate these drop down boxes ? on client side. Like if no value is selected that pass error to user that please select value.
I have added linq to sql classes which automatically generate things


@using (Html.BeginForm("Generated_PaySlip", "Home", FormMethod.Get))


             @Html.DropDownList("Month", "Select Date")
            Employee Name

             @Html.DropDownList("EmplID", "Select Name")
             <input type="submit" value="Submit" />




public ActionResult InfoFor_PaySlip() 
            var dates = (from ps in DataContext.MonthlyRecords select new {ps.Month }).Distinct();
            ViewData["Month"] = new SelectList(dates, "Month", "Month");

            var names = (from n in DataContext.HrEmployees select new { n.EmplID, n.EmplName }).Distinct();
            ViewData["EmplID"] = new SelectList(names, "EmplID", "EmplName");
            return View();
SP HINGU 13-Feb-14 7:40am
do you want to validate through model or custom client side javascript code?
for client side javascript validation you can simply check like this
Hunain Hafeez 13-Feb-14 7:51am
sir, client-side, a good and beatiful

You created dropdown you can use DropdownListFor And you can write ValidationMessagefor properties of MVC

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900