将出生日期传递给控制对象时{01/01/0001}

时间:2018-08-25 20:35:39

标签: validation asp.net-core-mvc razor-pages

我要保存一份注册表,并且必须以另一种格式保存出生日期。

在模型中,我有:

public DateTime BirthDate { get; set; }

在视图中:

@model Univer.Model.KarApplicant
@{
ViewData["Title"] = "";
}
 <div class="container MainMiddle" style="padding-top:50px;">
<hr />
<div class="row container-fluid">
    <div class="col-md-10">
        <form asp-action="Register">
            <div asp-validation-summary="ModelOnly" class="text-danger"> 
</div>

            <div class="form-row">
                ....
                <div class="form-group col-md-4">
                    <label asp-for="BirthDate" class="control-label"></label>
                    <div class="input-group mb-2 mr-sm-2">
                        <div class="input-group-prepend">
                            <div class="input-group-text"><i class="fas fa-calendar-alt"></i></div>
                        </div>
                        <input asp-for="BirthDate" class="form-control example1" data-val="false" />
                        <span asp-validation-for="BirthDate" class="text-danger"></span>
                    </div>
                </div>
            </div>
            ....
            <div class="form-row">
               </div>
                <div class="form-group float-left">
                    <input type="submit" value="next" class="btn btn-lg btn-primary btn-block" />
                </div>
            </div>
        </form>
    </div>
</div>


</div>
 @section Scripts {
  @{await Html.RenderPartialAsync("_ValidationScriptsPartial");}

<script src="~/lib/persian-date/persian-date.js"></script>
<script src="~/lib/persian-datepicker/js/persian-datepicker.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $(".example1").pDatepicker();
    });
</script>
}

当我单击Submit(提交)按钮并将数据发送到控制器的动作时,通过传递给控制器​​的断点检查 form value ,传递给控制器​​的生日日期值为01/01/0001,但是我在视图输入中以波斯模式具有价值。

我的问题是:为什么在输入中使用javascript设置值并将其发送给控制器时,该值无法发送?

更新:在评论之后我添加了此代码

public void ConfigureServices(IServiceCollection services)
    {
        services.Configure<RequestLocalizationOptions>(options =>
        {
            options.DefaultRequestCulture = new RequestCulture("fa-IR");
        }); .....
   }

 public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {....
        app.UseRequestLocalization();
        app.UseMvc()....
    }

0 个答案:

没有答案