Skip to content

Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.

Improvements with validation model during the checkout

KrzysztofPajak1328ad42eeeb
diff --git a/src/Web/Grand.Web/Controllers/CheckoutController.cs b/src/Web/Grand.Web/Controllers/CheckoutController.cs
index c7c6def1c..053612a7a 100644
--- a/src/Web/Grand.Web/Controllers/CheckoutController.cs
+++ b/src/Web/Grand.Web/Controllers/CheckoutController.cs
@@ -507,10 +507,12 @@ namespace Grand.Web.Controllers
else
{
//new address
- ModelState.Clear();
var model = new CheckoutBillingAddressModel();
await TryUpdateModelAsync(model.NewAddress, "BillingNewAddress");
+ ModelState.Clear();
+ TryValidateModel(model);
+
//custom address attributes
var customAttributes = await _mediator.Send(new GetParseCustomAddressAttributes() { Form = form });
var customAttributeWarnings = await _addressAttributeParser.GetAttributeWarnings(customAttributes);
@@ -661,9 +663,11 @@ namespace Grand.Web.Controllers
}
else
{
- ModelState.Clear();
//new address
await TryUpdateModelAsync(model.NewAddress, "ShippingNewAddress");
+ ModelState.Clear();
+ TryValidateModel(model);
+
//custom address attributes
var customAttributes = await _mediator.Send(new GetParseCustomAddressAttributes() { Form = form });
var customAttributeWarnings = await _addressAttributeParser.GetAttributeWarnings(customAttributes);