namespace DBLayer.Models
{
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
public partial class CustomerBasicDetail
{
[Required]
public string DOB { get; set; }
}
}
MVC View
@using (Html.BeginForm()) {
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
@Html.LabelFor(model => model.DOB) | @Html.EditorFor(model => model.DOB, new { id="Dob"}) @Html.ValidationMessageFor(model => model.DOB) |
I have a model and View like above.I need to add calender controller for that view.Can anyone tell me how to that?.
Nimit JoshiPosted Feb 17, 2014, 12:11 AM
Model:
public class Student
{
public int ID { get; set; }
public string DOB { get; set; }
}
public class StudentDbContext : DbContext
{
public DbSet<Student> Students { get; set; }
}
Controller:
public ActionResult Create()
{
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include="ID,DOB")] Student student)
{
if (ModelState.IsValid)
{
db.Students.Add(student);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(student);
}
View:
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>Studenth4>
<hr />
@Html.ValidationSummary(true)
<div class="form-group">
@Html.LabelFor(model => model.DOB, new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.DOB)
@Html.ValidationMessageFor(model => model.DOB)
div>
div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
div>
div>
div>
}
Jignesh TrivediPosted Feb 16, 2014, 11:31 PM
hi,
Jquery may help you to render datepicker
include js for UI element and write below code
please refer
http://jqueryui.com/datepicker/
hope this wil help you.