@model HelloWorldMvcApp.SampleViewModel
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bootstrap 101 Template</title>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
.field-validation-error {
<div class="col-md-6 col-md-offset-3">
@using (Html.BeginForm())
<div>Using the same name for both the model and ViewBag property and the DropDownListFor method. The value of CustomerA is "Client 2" but it is not selected</div>
@Html.LabelFor(m => m.CustomerA)
@Html.DropDownListFor(m => m.CustomerA, (IEnumerable<SelectListItem>)ViewBag.CustomerA, "Please select", new { @class="form-control"})
@Html.ValidationMessageFor(m => m.CustomerA)
<div>Using the same name for both the model and ViewBag property and the DropDownList method. There is no client side validation</div>
@Html.LabelFor(m => m.CustomerB)
@Html.DropDownList("CustomerB", (IEnumerable<SelectListItem>)ViewBag.CustomerB, "Please select", new { @class="form-control"})
@Html.ValidationMessageFor(m => m.CustomerB)
<div>Using different name for both the model and ViewBag property and the DropDownListFor method. The correct option is selected and there is client side validation</div>
@Html.LabelFor(m => m.CustomerC)
@Html.DropDownListFor(m => m.CustomerC, (IEnumerable<SelectListItem>)ViewBag.CustomerCList, "Please select", new { @class="form-control"})
@Html.ValidationMessageFor(m => m.CustomerC)
<button type="submit" class="btn btn-success submit">Submit</button>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<script src="//ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js"></script>
<script src="//ajax.aspnetcdn.com/ajax/mvc/4.0/jquery.validate.unobtrusive.min.js"></script>
<script type="text/javascript">