在MVC,Asp.net的波斯日历

时间:2013-04-27 06:04:37

标签: javascript asp.net-mvc calendar culture persian

我在MVC中使用DateTime变量,我想显示

的波斯日历
@Html.EditorFor(x=> x.ProductionDate)

我该怎么办?

3 个答案:

答案 0 :(得分:8)

我找到了解决方案

1.转到www.amib.ir/weblog/?page_id=316并下载最新版本的“AMIB_jsPersianCal”

2.将“js-persian-cal.min.js”和“js-persian-cal.css”和“pcal.png”添加到您的项目中
您可以更改指定PNG文件的URL的CSS。

3.将css和js文件添加到cshtml文件

<link href="@Url.Content("~/Content/js-persian-cal.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/js-persian-cal.min.js")"></script>


4.像

一样更改日期文件
@Html.TextBoxFor(m => m.Birthdate, new { @id = "pcal1", @class = "pdate" });

注意:我在Birthdate中使用字符串变量

5.将脚本添加到cshtml文件的末尾

<script type="text/javascript">
var objCal1 = new AMIB.persianCalendar('pcal1'); </script>

答案 1 :(得分:4)

尝试使用此模板(datetime.cshtml)自动显示/转换DateTime到PerisanDate:

@*
  Copy this file to:
  Views\Shared\DisplayTemplates\datetime.cshtml
*@

@using System.Globalization
@model Nullable<DateTime>

@helper ShamsiDateTime(DateTime info, string separator = "/", bool includeHourMinute = true)
{
    int ym = info.Year;
    int mm = info.Month;
    int dm = info.Day;
    var sss = new PersianCalendar();
    int ys = sss.GetYear(new DateTime(ym, mm, dm, new GregorianCalendar()));
    int ms = sss.GetMonth(new DateTime(ym, mm, dm, new GregorianCalendar()));
    int ds = sss.GetDayOfMonth(new DateTime(ym, mm, dm, new GregorianCalendar()));    
    if (includeHourMinute)
    {
        @(ys + separator + ms.ToString("00") + separator + ds.ToString("00") + " " + info.Hour + ":" + info.Minute)
    }
    else
    {
        @(ys + separator + ms.ToString("00") + separator + ds.ToString("00"))
    }
}

@if (@Model.HasValue)
{
  @ShamsiDateTime(@Model.Value , separator: "/", includeHourMinute: false)
}

另外,如果您正在寻找波斯日期时间选择器,请查看: http://www.dotnettips.info/newsarchive/details/1122

答案 2 :(得分:0)

web.config中尝试此操作:

 <system.web>
     <globalization culture="fa-IR" uiCulture="fa-IR" 
     requestEncoding="utf-8" 
     responseEncoding="utf-8" />
 </system.web>