Persian calendar in MVC, Asp.net

I use the DateTime variable in MVC and I want to show the Persian calendar for

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

How can i do this?

+5
source share
3 answers

I found solution

1. Before www.amib.ir/weblog/?page_id=316 and download the latest version of "AMIB_jsPersianCal"


2. Add "js-persian-cal.min.js" and "js-persian-cal.css" and "pcal.png" in your project,
you can change the css for the specified Url PNG file

3. Add the css and js file to the cshtml file

<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. modify your date file, for example

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

note: I use a string variable for the Birthdate


5.add script at the end of the cshtml file

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

(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

+4

try this in web.config:

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

All Articles