Click here to Skip to main content
15,892,697 members

How to use DateTime in MVC 3 with Razor (CSHTML)

perambulator747 asked:

Open original thread
I am having a lot of difficulty trying to start using the DateTimePicker/Calendar object from the Telerik ASP MVC Extensions toolbox kit. I want to REPLACE "@*<select id="Date" style="width:100px"></select>*@" WITH a DateTimePicker/Calendar object

C#
@{
ViewBag.Title = "Appointment Search";
Layout = "~/Views/Shared/_PhysioLayout.cshtml";

}

<h2>Appointment Search</h2>

<h2></h2>
<fieldset>
<h2>Please select a start date to generate schedule</h2><h6>Default is today</h6>
@*<select id="Date" style="width:100px">
</select>*@
<h2></h2>
<fieldset>
<legend>View By</legend>
<div><input id="Day" type="radio" /><h4>Day</h4></div>
<input id="Week" type="radio" /><h4>Week</h4>
<input id="Month" type="radio" /><h4>Month</h4>
<h2></h2>
</fieldset>
</fieldset>

@Html.ActionLink("Display Appointments", "Index")

<h2></h2>
<p>

@Html.ActionLink("Back to Home", "Index")
</p>


SQL
Basically, what I am trying to do, in the program, I am a physiotherapist, trying to search for different appointments that my patients have booked for, online. Instead of choosing the date and time from a drop down combo box, I want to display a DateTimePicker object or Calendar object where I can simply select a date and time and pass the value of date and time across to the controller where I can use it in other places in the program

I tried this method, as Carl Bergenhem displays in his video:

http://tv.telerik.com/watch/aspnet-mvc/getting-started-with-datetimepicker


C#
@(Html.Telerik().DateTimePicker()
.Name("MyDateTimePicker")
.Min(new DateTime(2011,1,1)
.Max(new DateTime(2012,1,1)
.Interval(30)
.Render()


But that only works in View pages that have been made in ASPX, which is not what I want

I also try doing this:

http://www.telerik.com/help/aspnet-mvc/getting-started-using-telerik-extensions-for-asp.net-mvc-in-your-project.html

But after getting to a point...when I type in Html., then "Telerik" doesn't appear in my Intellisense in Microsoft Visual Studio Ultimate 2010

Please suggest a simple tutorial on how to create the datetimepicker/calendar object in a View page that is made in Razor (CSHTML) in ASP.NET MVC 3. And also how to pass the values from there to a controller

Thank You
Tags: C# (C# 4.0), ASP.NET, MVC3, DateTime

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900