I am working on a mvc4 project.
Layout page:
<html lang="en">
<head>
<meta charset="utf-8" />
@Scripts.Render("~/bundles/MainScripts")
@Scripts.Render("~/bundles/JqueryUIScripts")
@Styles.Render("~/Content/MainCss")
@Styles.Render("~/Content/JqueryUICss")
</head>
<body>
@RenderBody()
</body>
</html>
Bundle:
//Script Bundles
//Basic Scripts
bundles.Add(new ScriptBundle("~/bundles/MainScripts").Include(
"~/Scripts/jQuery1.9.1.js",
//"~/Scripts/jquery-1.10.2.js",//For ui and fileupload plugin
"~/Scripts/jquery.validate.min.js",
"~/Scripts/jquery.validate.unobtrusive.js",
"~/Scripts/knockout-3.0.0.js",
"~/Scripts/jquery.ui.core.js",
"~/Scripts/jquery.ui.widget.js"
));
//Jquery UI Scripts
bundles.Add(new ScriptBundle("~/bundles/JqueryUIScripts").Include(
"~/Scripts/jquery-1.10.2.js",
"~/Scripts/jquery.ui.effect-slide.js",
"~/Scripts/jquery.ui.datepicker.js",
"~/Scripts/jquery.ui.effect-drop.js",
"~/Scripts/jquery.ui.position.js",
"~/Scripts/jquery.ui.menu.js",
"~/Scripts/jquery.ui.autocomplete.js"
));
//File Upload Scripts
bundles.Add(new ScriptBundle("~/bundles/FileUploadScripts").Include(
"~/Scripts/file-upload/jquery.fileupload.js",
"~/Scripts/file-upload/jquery.fileupload-ui.js",
"~/Scripts/file-upload/jquery.iframe-transport.js",
"~/Scripts/file-upload/jquery.form.js",
"~/Scripts/file-upload/jquery.uploadfile.js",
"~/Scripts/jquery.unobtrusive-ajax.js"
));
//Style Bundle
//Basic Css
bundles.Add(new StyleBundle("~/Content/MainCss").Include(
"~/Content/css/inner.css"
));
//Jquery UI Css
bundles.Add(new StyleBundle("~/Content/JqueryUICss").Include(
"~/Content/css/jquery.ui.datepicker.css",
"~/Content/css/jquery.ui.all.css",
"~/Content/css/jquery.ui.theme.css",
"~/Content/css/jquery.ui.core.css",
"~/Content/css/jquery.ui.autocomplete.css"
));
//File Upload Css
bundles.Add(new StyleBundle("~/Content/FileUploadCss").Include(
"~/Content/css/uploadfile.css"
));
Root web.config:
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
View Model with using System.ComponentModel.DataAnnotations:
public class EmployeeVM
{
public Int32 EmployeeId { get; set; }
[Required]
public string FirstName { get; set; }
[Required]
public string LastName { get; set; }
}
View passing this 'EmployeeVM':
@model addsds.Web.ViewModels.EmployeeVM
@Scripts.Render("~/bundles/FileUploadScripts")
@Styles.Render("~/Content/FileUploadCss")
@using (Html.BeginForm("Add", "Employee"))
{
@Html.ValidationSummary(true);
@Html.Label("First Name", new { @class = "lable" })
@Html.TextBoxFor(m => m.FirstName, new { @class = "input-box" })
@Html.Label("Last Name", new { @class = "lable" })
@Html.TextBoxFor(m => m.LastName, new { @class = "input-box" })
<input type="submit" name="action:Add" title="" value="Save" class="button">
}
Client side validation is not working...It directs to the controller method when button save is clicked. I want the textbox of FirstName and LastName to have border red when empty before the hit to controller. What am i missing?