C# 使用HTML辅助标记添加日历控件

C# 使用HTML辅助标记添加日历控件,c#,asp.net,asp.net-mvc-3,C#,Asp.net,Asp.net Mvc 3,我需要知道如何使用HTML助手标记添加日历。我发现了一个名为的第三方库,但是在VisualStudio工具箱中提供的组件中有什么我可以使用的吗 注意:我还需要为所选日期上色,启用/禁用日历中的某些日期如果我正确理解了您的问题,只需将工具栏上的日历控件拖到表单上即可。然后您可以访问它的属性以相应地影响日历。如果您使用的是Asp.net mvc3,请尝试此代码 using System; using System.Collections.Generic; using System.Glo

我需要知道如何使用
HTML助手
标记添加
日历
。我发现了一个名为的第三方库,但是在VisualStudio工具箱中提供的组件中有什么我可以使用的吗


注意:我还需要为所选日期上色,启用/禁用日历中的某些日期

如果我正确理解了您的问题,只需将工具栏上的日历控件拖到表单上即可。然后您可以访问它的属性以相应地影响日历。

如果您使用的是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());
    }
}
使用系统;
使用System.Collections.Generic;
利用制度全球化;
使用System.Linq;
使用系统文本;
使用System.Web;
使用System.Web.Mvc;
是的,助手
{
公共静态类日历扩展
{
公共静态IHtmlString日历(此HtmlHelper帮助程序,DateTime dateToShow)
{
DateTimeFormatInfo cinfo=DateTimeFormatInfo.CurrentInfo;
StringBuilder sb=新的StringBuilder();
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.追加(“+cinfo.MonthNames[date.Month-1]+”+dateToShow.Year+”);
对于(int i=0;i<((天+空细胞)>35?42:35);i++)
{
如果(i%7==0)
{
如果(i>0)某人加上(“”);
某人加上(“”);
}
如果(i=emptyCells+天)
{
某人加上(“”);
}
其他的
{
某人加上(“+日期+”);
日期=日期。添加天数(1);
}
}
某人加上(“”);
返回helper.Raw(sb.ToString());
}
}

}

有人能告诉我如何使用jquery在mvc中翻页吗?我应该在哪里添加此功能?它是到HomeController.cs的吗?它是一个HTML帮助程序..要在视图中使用它,请使用此代码..是的,但我无法单击日历、更改月/年等。这是如何完成的?只需调用我也必须传递一些参数?当我添加带有0个参数的代码时,它不起作用。当我给出我不允许单击或更改日历的日期时,我认为他/她正在使用MVC,因此从工具箱拖动控件在这里不是一个真正的选项。