2013-02-13 54 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