.net - .NET 5 (Core) MVC - 使用 en-GB 的模型绑定 DateTime 不能在 GET 上工作,但在 POST 上工作正常
问题描述
我有一个配置的新 .NET 5 Web 应用程序:
public void ConfigureServices(IServiceCollection services)
{
services.Configure<RequestLocalizationOptions>(
opts =>
{
var supportedCultures = new List<CultureInfo> {new CultureInfo("en-GB"),};
opts.SupportedCultures = supportedCultures;
opts.SupportedUICultures = supportedCultures;
opts.DefaultRequestCulture = new RequestCulture(culture: "en-GB", uiCulture: "en-GB");
});
services.AddControllersWithViews();
}
然后我正在使用:
app.UseRequestLocalization();
app.UseRouting();
我的测试表格:
<form method="get" asp-action="TestGet" asp-controller="Home">
<h2>test get</h2>
<input type="text" id="From" name="From" value="15/12/2020">
<button type="submit">go</button>
</form>
<form method="post" asp-action="TestPost" asp-controller="Home">
<h2>test post</h2>
<input type="text" id="From" name="From" value="15/12/2020">
<button type="submit">go</button>
</form>
我的行动:
[HttpGet]
public RedirectResult TestGet(DateTime from)
{
var me = from;
return Redirect("/");
}
[HttpPost]
public RedirectResult TestPost(DateTime from)
{
var me = from;
return Redirect("/");
}
预期的结果是日期在两种情况下都有约束,但这仅适用于邮寄。在获取日期未设置。
我究竟做错了什么?
解决方案
好的,找到问题了。它的设计是不变的 - 因此允许共享查询字符串。
推荐阅读
- html - 事件前的下拉显示
- java - Functional programming problem over elements of a stream
- python - Python: handling large numbers
- php - 在 PHP 中通过 JS 块中的数据爬行
- univocity - @Validate 在 UniVocity 解析器中与 CsvRoutines 一起使用时不会跳过无效行
- for-loop - 如何在此代码中使用 for 循环与 while 循环
- go - 配置结构接收器以使用某种类型
- google-cloud-platform - 谷歌云浏览器 ssh 下载功能异常
- mysql - 选择体育赛事较少的5个运动项目
- pyspark - Pyspark 不工作并抛出 java 异常:Java 网关进程在发送其端口号之前退出