【问题标题】:Persian Calender in MVC , Asp.netMVC , Asp.net 中的波斯日历
【发布时间】:2013-04-27 06:04:36
【问题描述】:

我在 MVC 中使用 DateTime 变量,我想显示波斯日历

@Html.EditorFor(x=> x.ProductionDate)

我该怎么做?

【问题讨论】:

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


    【解决方案1】:

    我找到了解决方案

    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" });
    

    注意:我使用字符串变量作为生日


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

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

    【讨论】:

    • 为什么你没有标记到 javascript?!
    • 我想在 .NET 中使用波斯文化,但我找不到解决问题的方法,因此我使用 JavaScript 来绕过问题
    【解决方案2】:

    试试这个模板 (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

    【讨论】:

      【解决方案3】:

      web.config 试试这个:

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

      【讨论】:

        【解决方案4】:

        使用波斯日历作为 html 助手与标签生成器 c#、MVC 并将选定的波斯日期转换为公历日期

        使用 JS、HTML、CSS、C# 波斯日历的白色主题,易于使用。 创建波斯日历作为 html 助手。 使用 c# 中的标记生成器来构建 html 帮助程序 (MVCHtmlString)。 将选定的波斯日期转换为公历日期。 不允许对输入进行编辑。 为输入和日历创建随机 ID。

        访问https://github.com/tarqawwad/Persian-Calendar

        Click here to show example

        【讨论】:

        • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
        • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-10-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多