@model Uploader.Controllers.OperationModel
@using (Html.BeginForm("Register", "Home", FormMethod.Post, null))
{
@Html.LabelFor(model => model.OperationId, "Operation Name ", new { @class = "control-label" })<b class="mandatory"> * </b><b>:</b>
@Html.EJS().DropDownList("OperationId").Width("300").ShowClearButton(true).Placeholder("Select a Operation").FilterBarPlaceholder("Search Operation").AllowFiltering(true).DataSource((List<OperationModel>)ViewBag.OperationId).Fields(new DropDownListFieldSettings { Text = "OperationName", Value = "OperationId" }).Value(ViewBag.Value).Render()
@Html.ValidationMessageFor(model => model.OperationId, "", new { @class = "text-danger" })
<br />
<input type="submit" value="Save" class="btn btn-default" />
}
|
public class HomeController : Controller
{
OperationModel model = new OperationModel();
public ActionResult Index()
{
ViewBag.OperationId= OperationModel.GetAllRecords();
ViewBag.Value = "1006";
return View();
}
public ActionResult Register(OperationModel model)
{
ViewBag.OperationId = OperationModel.GetAllRecords();
if (ModelState.IsValid)
{
//perform required action after validation.
}
return View("Index");
}
}
public class OperationModel
{
[Required(ErrorMessage ="Please Select an Item")]
public string OperationId { get; set; }
public string OperationName { get; set; }
public OperationModel()
{
}
public OperationModel(string OperationId, string OperationName)
{
this.OperationId = OperationId;
this.OperationName = OperationName;
}
public static List<OperationModel> GetAllRecords()
{
List<OperationModel> order = new List<OperationModel>();
order.Add(new OperationModel("1001", "ALFKI"));
order.Add(new OperationModel("1002", "ANATR"));
order.Add(new OperationModel("1003", "ANTON"));
order.Add(new OperationModel("1004", "BLONP"));
order.Add(new OperationModel("1005", "BOLID"));
order.Add(new OperationModel("1006", "MARTIN"));
order.Add(new OperationModel("1007", "CACTU"));
order.Add(new OperationModel("1008", "VINCET"));
order.Add(new OperationModel("1009", "JOHN"));
order.Add(new OperationModel("1010", "MATHEW"));
return order;
}
} |