Fix/8392 remeber me model state exception (#8410)

@sebastienros this fixes the possible NRE that would happen for absent models from merged #8393 
(see your comment there https://github.com/OrchardCMS/Orchard/pull/8393#issuecomment-686630198)
This commit is contained in:
Hermes Sbicego
2020-09-04 09:12:10 +02:00
committed by GitHub
parent c566e12abd
commit 3ceda381c5

View File

@@ -16,6 +16,7 @@ namespace Orchard.Mvc.ModelBinders {
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) {
var value = false;
if (string.IsNullOrWhiteSpace(controllerContext.HttpContext.Request[bindingContext.ModelName])) return false;
var requestBooleanValue = controllerContext.HttpContext.Request[bindingContext.ModelName].Split(',')[0]; //Html.CheckBox and Html.CheckBoxFor return "true,false" string
if (!bool.TryParse(requestBooleanValue, out value)) {
bindingContext.ModelState.AddModelError(bindingContext.ModelName, new FormatException());