asp.netcore日期控件无法发送到控制器。
创始人
2024-09-18 05:30:41
0

可能会有几种

  1. 确保您在表单中包含了一个名为“date”的input元素,例如:

  1. 确保您的ASP.NET Core控制器具有与input元素名称匹配的参数。例如:

public IActionResult MyAction(DateTime date) { // do something with the date parameter }

  1. 如果您希望将日期值以不同的格式发送回控制器,则需要使用自定义模型绑定器。例如:

public class CustomDateTimeModelBinder : IModelBinder { public Task BindModelAsync(ModelBindingContext bindingContext) { var value = bindingContext.ValueProvider.GetValue(bindingContext.ModelName); DateTime result;

    if (!DateTime.TryParseExact(value.FirstValue, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out result))
    {
        // return an error if the date is in an incorrect format
        bindingContext.ModelState.AddModelError(bindingContext.ModelName, "Invalid date format. The date must be in the format dd/MM/yyyy.");
    }

    bindingContext.Result = ModelBindingResult.Success(result);
    return Task.CompletedTask;
}

}

然后,在控制器中,您需要将参数注释为使用自定义模型绑定器,例如:

public IActionResult MyAction([ModelBinder(BinderType = typeof(CustomDateTimeModelBinder))]DateTime date) { // do something with the date parameter }

这些方法中的一个可能会解决您的问题。

相关内容

热门资讯

透视辅助(aapoker外挂)... 透视辅助(aapoker外挂)菠萝德州偷偷看功能(详细辅助透视教程)切实是有挂;透视辅助(aapok...
透视透视(wepOke)透明挂... 1、透视透视(wepOke)透明挂辅助神器(wepoke有没有挂)往昔有挂(详细透视力荐教程)(UU...
微扑克辅助挂!wpk开挂实锤,... 微扑克辅助挂!wpk开挂实锤,(aa poker)果然真的有挂(详细透视透视教程);1分钟了解详细教...
透视科技(微扑克wpk透视辅助... 透视科技(微扑克wpk透视辅助)wepoke软件能玩吗(详细辅助2025新版总结)原来真的有挂是一款...
透视脚本(wepoKE)透视辅... 透视脚本(wepoKE)透视辅助代打(aapoker透明挂)总是真的有挂(详细透视AI教程);玩家必...
wepoke确实有挂!wepo... wepoke确实有挂!wepoke辅助软件下载,(WepoKe)确实有挂(详细辅助必胜教程);支持2...
透视模拟器(wepower有外... 透视模拟器(wepower有外挂)aapoker辅助工具(详细辅助技巧教程)其实存在有挂1、这是跨平...
aapoker透视辅助!微扑克... aapoker透视辅助!微扑克有假吗,(AApOKER)起初真的有挂(详细辅助系统教程);亲真的是有...
透视计算(WEPoke)透明挂... 1、透视计算(WEPoke)透明挂辅助软件(wepoke智能ai)其实是真的有挂(详细透视存在挂教程...
透视存在(德扑ai智能)德扑统... 透视存在(德扑ai智能)德扑统计软件(详细辅助科技教程)原本真的是有挂1、金币登录送、破产送、升级送...