如何在带有Razor(CSHTML)的MVC 3中使用DateTime [英] How to use DateTime in MVC 3 with Razor (CSHTML)
问题描述
尝试从Telerik ASP MVC扩展工具箱工具包开始使用DateTimePicker/Calendar对象时遇到很多困难.我想用DateTimePicker/Calendar对象替换"@ *
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
@{
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>
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
@(Html.Telerik().DateTimePicker()
.Name("MyDateTimePicker")
.Min(new DateTime(2011,1,1)
.Max(new DateTime(2012,1,1)
.Interval(30)
.Render()
但这仅适用于用ASPX制作的View页面,这不是我想要的
我也尝试这样做:
http://www.telerik.com/help/aspnet-mvc/getting-started-using-telerik-extensions-for-asp.net-mvc-in-your-project.html
但是到了要点...当我键入HTML时,"Telerik"并没有出现在Microsoft Visual Studio Ultimate 2010的Intellisense中.
请提出一个简单的教程,介绍如何在ASP.NET MVC 3中以Razor(CSHTML)制作的View页面中创建datetimepicker/calendar对象,以及如何将值从那里传递给控制器.
谢谢您
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
推荐答案
视图顶部是否有@using Telerik.Web.Mvc.UI
指令?然后,在Views文件夹中的web.config 中是否包含以下内容,而不是在根文件夹 1 中的不是 web.config中: br/>
Do you have a@using Telerik.Web.Mvc.UI
directive at the top of your view? Then, do you have the following in your web.config in your Views folder, not the web.config in the root folder1:
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
...
<add namespace="Telerik.Web.Mvc" />
<add namespace="Telerik.Web.Mvc.UI" />
</namespaces>
</pages>
</system.web.webPages.razor>
然后,最简单的教程"或快速入门是查看Telerik示例中的控制器代码和Razor视图代码.如果选择安装它们,则可以在本地找到它们,或者可以在网上找到它们.
1 我怀疑在所有想要的web.config中都包含这些内容会很痛,但是必须在Views文件夹配置中.
Then, the simplest ''tutorial'' or quickstart is to look at the controller code and the Razor view code in the Telerik exmaples. You can find these locally if you chose to install them, or they are available online.
1 I doubt it hurts to have these in all the web.configs you want to, but it must be in the Views folder config.
这篇关于如何在带有Razor(CSHTML)的MVC 3中使用DateTime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!