波斯日历中的MVC,Asp.net(Persian Calender in MVC , Asp.ne

2019-09-01 05:49发布

我使用MVC日期时间变量,我想表明波斯压延

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

我该怎么做?

Answer 1:

我找到了解决办法

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


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

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.change喜欢你的号文件

@Html.TextBoxFor(m => m.Birthdate, new { @id = "pcal1", @class = "pdate" });

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


5.add脚本CSHTML文件的末尾

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


Answer 2:

试试这个模板(datetime.cshtml)来显示/转换日期时间自动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



Answer 3:

试试这个在web.config

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


文章来源: Persian Calender in MVC , Asp.net