2013-02-13 26 views
0

我需要知道如何使用HTML helper标记添加Calendar。我找到了一个名为Kendo的第三方库,但是我可以在Visual Studio工具箱中自带的组件中使用它。使用HTML帮助程序标记添加日历控件

注:我还需要在日历

+0

谁能告诉我如何翻转MVC中使用jQuery的网页? – Neel 2013-02-13 07:09:03

回答

0

到颜色选择的日期,启用/禁用特定日期如果我正确理解你的问题,只是Ddrag从工具栏Calendar控件到窗体。然后,您可以访问它的属性来相应地生成日历。

+1

我认为他/她正在使用MVC,因此从工具箱中拖动控件在这里并不是真正的选择。 – 2013-02-13 09:07:20

1

如果您正在使用Asp.net MVC3那么试试这个代码..

using System; 
    using System.Collections.Generic; 
    using System.Globalization; 
    using System.Linq; 
    using System.Text; 
    using System.Web; 
    using System.Web.Mvc; 

namespace AntiYes.Helpers 
{ 
public static class CalendarExtensions 
{ 
    public static IHtmlString Calendar(this HtmlHelper helper, DateTime dateToShow) 
    { 
     DateTimeFormatInfo cinfo = DateTimeFormatInfo.CurrentInfo; 
     StringBuilder sb = new StringBuilder(); 
     DateTime date = new DateTime(dateToShow.Year, dateToShow.Month, 1); 
     int emptyCells = ((int)date.DayOfWeek + 7 - (int)cinfo.FirstDayOfWeek) % 7; 
     int days = DateTime.DaysInMonth(dateToShow.Year, dateToShow.Month); 
     sb.Append("<table class='cal'><tr><th colspan='7'>" + cinfo.MonthNames[date.Month - 1] + " " + dateToShow.Year + "</th></tr>"); 
     for (int i = 0; i < ((days + emptyCells) > 35 ? 42 : 35); i++) 
     { 
      if (i % 7 == 0) 
      { 
       if (i > 0) sb.Append("</tr>"); 
       sb.Append("<tr>"); 
      } 

      if (i < emptyCells || i >= emptyCells + days) 
      { 
       sb.Append("<td class='cal-empty'>&nbsp;</td>"); 
      } 
      else 
      { 
       sb.Append("<td class='cal-day'>" + date.Day + "</td>"); 
       date = date.AddDays(1); 
      } 
     } 
     sb.Append("</tr></table>"); 
     return helper.Raw(sb.ToString()); 
    } 
} 

}

+0

我应该在哪里添加此功能?它是到HomeController.cs? – 2013-02-13 07:24:40

+0

它是一个HTML助手。要在视图中使用此代码,请使用此代码。<%= Html.Calendar(new DateTime(2012,4,1))%> – coder 2013-02-13 07:31:16

+0

是的,但我无法点击日历,更改月/年等等。这是如何完成的? – 2013-02-13 07:43:25