Asp.net mvc 3 日期的MVC3文本框为美式格式。想要英国格式吗

Asp.net mvc 3 日期的MVC3文本框为美式格式。想要英国格式吗,asp.net-mvc-3,datetime,model,Asp.net Mvc 3,Datetime,Model,在我的模型中,我使用两个日期属性:开始日期和结束日期。我已经将这两个属性映射到两个textboxfortextboxs。当页面加载这两个日期是美国格式,但我希望它是英国格式 @model UserManager.Models.vw_Group_Model @{ ViewBag.Title = "Edit Group"; } @using (Html.BeginForm()) { @Html.ValidationSummary(true) <div id="e

在我的模型中,我使用两个日期属性:开始日期和结束日期。我已经将这两个属性映射到两个textboxfortextboxs。当页面加载这两个日期是美国格式,但我希望它是英国格式

    @model UserManager.Models.vw_Group_Model
@{
    ViewBag.Title = "Edit Group";
}
@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)
    <div id="edit-user" style="padding:25px;">
        <fieldset>
            <legend>Edit group details</legend>

            @* <div class="editor-label">
                @Html.LabelFor(model => model.companyId)
            </div>*@
           @* <div class="editor-field">
                @Html.EditorFor(model => model.companyId)  - Non editable
                @Html.ValidationMessageFor(model => model.companyId)
            </div>*@
            <div class="editor-label">
                @Html.LabelFor(model => model.RowType)
            </div>
            <div class="editor-field">
                @Html.TextBoxFor(model => model.RowType, new { @readonly = "readonly" })  - Non editable
                @Html.ValidationMessageFor(model => model.RowType)
            </div>
            <div class="editor-label">
                @Html.LabelFor(model => model.groupName)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.groupName) 
                @Html.ValidationMessageFor(model => model.groupName)
            </div>
            <div class="editor-label">
                @Html.LabelFor(model => model.companyName)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.companyName)  - Non editable
                @Html.ValidationMessageFor(model => model.companyName)
            </div>
          @*  <div id="hiddenSelection">
                @Html.HiddenFor(model => model.selected_company, new { id = "hdnCompany" }) 
                  @Html.HiddenFor(model => model.selected_group, new { id = "hdnGroup" }) 
            </div>*@
            @*<fieldset style="width: 400px; padding-left: 15px;">
                <legend>New company</legend>
                <div id="createuser-companysearch">
                    @{Html.RenderAction("_txtAutocompleteCompanySearch", "GroupManager");}
                </div>
            </fieldset>*@

            @* <fieldset style="width: 400px; padding-left: 15px;">
                <legend>New group</legend>
                <div id="createuser-groupsearch">
                    @{Html.RenderAction("_txtGroupSearchForm", "GroupManager");}
                </div>
            </fieldset>*@
            <div class="editor-label">
                @Html.LabelFor(model => model.StartDate)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.StartDate)
                @Html.ValidationMessageFor(model => model.StartDate)
            </div>
            <div class="editor-label">
                @Html.LabelFor(model => model.EndDate)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.EndDate)
                @Html.ValidationMessageFor(model => model.EndDate)
            </div>
            <div class="editor-label">
                @Html.LabelFor(model => model.IsActive)
            </div>
            <div class="editor-field">
                @Html.CheckBoxFor(model => model.IsActive)
                @Html.ValidationMessageFor(model => model.IsActive)
            </div>
            <p>
                <input type="submit" value="Edit" />
            </p>
            @Html.ValidationSummary()
            <br />
            @Html.ActionLink("Back to Group Manager Dashboard", "Index")
        </fieldset>
    </div>
}
<script type="text/javascript">



    $(document).ready(function () {
//        chkSelection();

        // Non editable fields grey
        $("#oldCompanyName").css("background-color", "gray");
        $("#oldGroupName").css("background-color", "gray");
        $("#RowType").css("background-color", "gray");


        // Assume group name already exists based on it being a value loaded from model
        var valueCompany = $("#oldCompanyName").val();
//        $("#hdnCompany").val(valueCompany);
        $('#selected_company').val(valueCompany);

        var valueGroup = $("#oldGroupName").val();
//        $("#hdnGroup").val(valueGroup);
//        $('#groupName').val(valueGroup);
        $('#txtGroupnameExistsAlf').css("background-color", "#33ff00").val('ALF group does exist');
        $('#txtGroupnameExistsBrad').css("background-color", "#33ff00").val('BRAD group does exist');



        var rowType = $('#RowType').val();
        if (rowType == "ALF") {

            var company = $('#companyName').val();
            $("#company_name").val(company);
            $('#txtCompanynameExistsAlf').css("background-color", "#F7D358").val('Company does exist');


        }
        else {
            var company = $('#companyName').val();
            $("#company_name").val(company);
            $('#txtCompanynameExistsBrad').css("background-color", "#F7D358").val('Company does exist');

        }

    });

</script>


@*
  $("#groupName").autocomplete({
        source: function (request, response) {
            $.ajax({
                url: '@Url.Action("LookUpGroupName", "UserManager")',
                dataType: "json",
                data: {
                    featureClass: "P",
                    style: "full",
                    maxRows: 12,
                    value: request.term
                },
                success: function (data) {
                    response($.map(data, function (item) {
                        //                            alert(item.group);
                        return {
                            label: item.group,
                            value: item.group
                        } // end of return

                    })); // end of response

                }, // end of success
                error: function (jqXHR, textStatus, errorThrown) {
                    alert(textStatus);
                } // end of error
            }); // end of ajax
        },
        minLength: 2,
        select: function (event, ui) { // Assign to hidden values to trigger onchange ajax call.

            $.ajax({
                url: '@Url.Action("GroupnameCheck", "UserManager")',
                dataType: "json",
                data: {
                    featureClass: "P",
                    style: "full",
                    maxRows: 12,
                    value: ui.item.label
                },
                success: function (data) {
                    $.each(data, function (index, value) {
                        if (index == "AlfGroup") {
                            $("#txtGroupnameExistsAlf").val(value);
                            if ($("#txtGroupnameExistsAlf").val() == "Alf Group doesn't exist.") {
                                $("#txtGroupnameExistsAlf").css("background-color", "red");
                            }
                            else {
                                $('#txtGroupnameExistsAlf').css("background-color", "#33ff00");
                            }
                        }

                        if (index == "BradGroup") {
                            $("#txtGroupnameExistsBrad").val(value);
                            if ($("#txtGroupnameExistsBrad").val() == "Brad Group doesn't exist.") {
                                $("#txtGroupnameExistsBrad").css("background-color", "red");
                            }
                            else {
                                $('#txtGroupnameExistsBrad').css("background-color", "#33ff00");
                            }
                        }
                        var selectedVal = $("#groupName").val();
                        $('#hdnGroup').val(selectedVal);

                    });
                }, // end of success
                error: function (jqXHR, textStatus, errorThrown) {
                    alert(textStatus);
                } // end of error
            }); // end of ajax

            $('#hdnGroupAlf').val(ui.item.label);
            $('#hdnGroupBrad').val(ui.item.label);
        },
        open: function () {
            $(this).removeClass("ui-corner-all").addClass("ui-corner-top");
        },
        close: function () {
            $(this).removeClass("ui-corner-top").addClass("ui-corner-all");
        }
    });


    $("#selected_company").autocomplete({
        source: function (request, response) {
            $.ajax({
                url: '@Url.Action("LookUpCompanyName", "GroupManager")',
                dataType: "json",
                data: {
                    featureClass: "P",
                    style: "full",
                    maxRows: 12,
                    value: request.term + ":" + $('#RowType').val()
                },
                success: function (data) {
                    response($.map(data, function (item) {
                        //                            alert(item.group);
                        return {
                            label: item.group,
                            value: item.group
                        } // end of return

                    })); // end of response

                }, // end of success
                error: function (jqXHR, textStatus, errorThrown) {
                    alert(textStatus);
                } // end of error
            }); // end of ajax
        },
        minLength: 2,
        select: function (event, ui) { // Assign to hidden values to trigger onchange ajax call.
            $('#hdnCompany').val(ui.item.label);
        }
    });

    function chkSelection() {
        if($('#RowType').text() == "ALF") {
            $('#companyname-checker-brad').hide();
            $('#groupname-checker-brad').hide();
        }
        else {
            $('#companyname-checker-alf').hide();
            $('#groupname-checker-alf').hide();
        }

    }*@
当前,页面上显示的日期如下:

01/01/0001

有人知道如何改变这个吗?最好是快速修复。谢谢。

我最后编写了这个javascript来拆分日期字符串,然后根据需要重新排列它

 function dateFormater() {
        var date = $('#StartDate').val()
        var arrDate = date.split("/");
        $('#StartDate').val(arrDate[1] + "/" + arrDate[0] + "/" + arrDate[2]);

        date, arrDate = null;

        date = $('#EndDate').val()
        arrDate = date.split("/");
        $('#EndDate').val(arrDate[1] + "/" + arrDate[0] + "/" + arrDate[2]);
    };

有人知道如何更改吗?在您的模型中尝试这样做:
[DisplayFormat(ApplyFormatInEditMode=true,DataFormatString=“{0:d}”)]
@model.StartDate.ToString(“dd/MM/yyyy”)
替换为您的TextBoxFor值中的
@model.StartDate
。@Karthik我尝试了您的建议,但没有改变任何内容。这应该不会这么难。是javascript改变了它吗?我正在使用jquery和jquery ui。是的,可能是因为jquery正在推动使用
US
日期格式。检查一下,还有这个。
 function dateFormater() {
        var date = $('#StartDate').val()
        var arrDate = date.split("/");
        $('#StartDate').val(arrDate[1] + "/" + arrDate[0] + "/" + arrDate[2]);

        date, arrDate = null;

        date = $('#EndDate').val()
        arrDate = date.split("/");
        $('#EndDate').val(arrDate[1] + "/" + arrDate[0] + "/" + arrDate[2]);
    };