Вопрос

Есть ли где -нибудь кто -то, кто сделал картирование C# DateFormat с DatePicker DateFormat, поскольку я уже знаю C# DateFormat, я не хочу проверять документацию DatePicker каждый раз, когда мне приходится создавать пользовательский формат даты.

Для Exmple, я хочу иметь возможность указать в моем помощнике DateFormat 'dd/Mm/yy' (c#), и это преобразовает его в Dd/Mm/yy 'DatePicker

Это было полезно?

Решение

Одним из возможных подходов было бы непосредственно заменить спецификаторы формата .NET своими аналогами jQuery, как вы можете увидеть в следующем коде:

public static string ConvertDateFormat(string format)
{
    string currentFormat = format;

    // Convert the date
    currentFormat = currentFormat.Replace("dddd", "DD");
    currentFormat = currentFormat.Replace("ddd", "D");

    // Convert month
    if (currentFormat.Contains("MMMM"))
    {
        currentFormat = currentFormat.Replace("MMMM", "MM");
    }
    else if (currentFormat.Contains("MMM"))
    {
        currentFormat = currentFormat.Replace("MMM", "M");
    }
    else if (currentFormat.Contains("MM"))
    {
        currentFormat = currentFormat.Replace("MM", "mm");
    }
    else
    {
        currentFormat = currentFormat.Replace("M", "m");
    }

    // Convert year
    currentFormat = currentFormat.Contains("yyyy") ? currentFormat.Replace("yyyy", "yy") : currentFormat.Replace("yy", "y");

    return currentFormat;
}

Первоначальный источник: http://rajeeshcv.com/2010/02/28/jqueryui-datepicker-in-asp-net-mvc/

Другие советы

Может, вы можете использовать что -то вроде этого:

<%= Html.TextBoxFor(x => x.SomeDate, new { @class = "datebox", dateformat = "dd/mm/yy" })%>

и это:

$(function() {
    $("input.datebox").each(function() {
        $(this).datepicker({ dateFormat: $(this).attr("dateFormat") });
    });
});
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top