I am fairly new to MVC3, and am building a SQL 2008 R2, EF4 website with it. In the last 36 hours, I have attempted to add Telerik's MVC extensions to the project in the hopes of using the DatePicker, Menu, etc. I believe that my configuration & installation are good, and some small tests (panel bar example) that I've done seem to confirm that, and my edits to the _layout.cshtml file also seem like they are good.
Where I'm stuck is attempting to integrate the Razor code examples for the Datepicker ( http://demos.telerik.com/aspnet-mvc/razor/datepicker ) to my existing project. I would like to add a Datepicker to a "date of birth" (DOB) field in my application's Profile page. The Profile has a table in the database, a model (profile.cs), a controller (ProfileController.cs) and some views in a Views/Profile directory (Index, Edit, etc.) All of the examples seem to focus on creating entirely new projects, new models, new controllers, etc. and because of my relative inexperience, I'm a little stuck on how to use the demo code outlined in my existing project.
I am assuming that I can place this partial class into my ProfileController.
public partial class DatePickerController : Controller
{
public ActionResult FirstLook(FirstLookModelView viewModel)
{
viewModel.DatePickerAttributes.SelectedDate = viewModel.DatePickerAttributes.SelectedDate ?? DateTime.Today;
viewModel.DatePickerAttributes.MinDate = viewModel.DatePickerAttributes.MinDate ?? new DateTime(1900, 1, 1);
viewModel.DatePickerAttributes.MaxDate = viewModel.DatePickerAttributes.MaxDate ?? new DateTime(2099,
12, 31);
viewModel.DatePickerAttributes.ShowButton = viewModel.DatePickerAttributes.ShowButton ?? true;
viewModel.DatePickerAttributes.OpenOnFocus = viewModel.DatePickerAttributes.OpenOnFocus ?? false;
return View(viewModel);
}
}
And that I can put the View elements into my Edit.cshtml where my @Html.EditorFor(model => model.DOB) is now
@(Html.Telerik().DatePicker()
.Name("DatePicker")
.HtmlAttributes(new { id = "DatePicker_wrapper" })
.Min(Model.DatePickerAttributes.MinDate.Value)
.Max(Model.DatePickerAttributes.MaxDate.Value)
.ShowButton(Model.DatePickerAttributes.ShowButton.Value)
.Value(Model.DatePickerAttributes.SelectedDate.Value)
)
@using (Html.Configurator("The date picker should...")
.PostTo("FirstLook", "DatePicker")
.Begin())
{
<ul>
<li>
@Html.CheckBox("DatePickerAttributes.ShowButton", Model.DatePickerAttributes.ShowButton.Value)
<label for="DatePickerAttributes_ShowButton">show a popup button</label>
</li>
<snip>
But I am fairly confused about where to put the section of code for the model...
public class FirstLookModelView
{
public FirstLookModelView()
{
DatePickerAttributes = new DatePickerAttributes();
}
public DatePickerAttributes DatePickerAttributes { get; set; }
}
Does that go into my current model Profile.cs? Any guidance would be appreciated.
PS I'm asking on the Telerik forums as well: http://www.telerik.com/community/forums/aspnet-mvc/documentation/difficulty-with-existing-project-and-adding-telerik-mvc-to-it.aspx