Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i am using MVC 3 asp.net 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

VIEW:

CSS
@using (Html.BeginForm("Generated_PaySlip", "Home", FormMethod.Get))
{
    <fieldset>

            Months 

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

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

     

    </fieldset>
    
    
}


Controller:

C#
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();
        }
Posted
Comments
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
$('#Month').val()==""
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
 
Share this answer
 

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