public override RegisterModel PrepareRegisterModel(RegisterModel model, bool excludeProperties, string overrideCustomCustomerAttributesXml = "", bool setDefaultValues = false)
{
if (!model.CustomProperties.ContainsKey("MyCustomProperty"))
{
model.CustomProperties.Add("MyCustomProperty"," ");
}
return base.PrepareRegisterModel(model, excludeProperties, overrideCustomCustomerAttributesXml, setDefaultValues);
}
@Html.EditorFor(model => model.CustomProperties["MyCustomProperty"])
First Issue : if we dont give any value to the custome property, editor is not shown on the view.
model.CustomProperties.Add("MyCustomProperty","");Editor is not shown on the view.
model.CustomProperties.Add("MyCustomProperty"," ");Editor is shown on the view.
I filled the form and also MyCustomProperty and then click save button. In the register action
ı can catch the value of my property like this
string myCustomProperty = (model.CustomProperties["MyCustomProperty"] as string[]).FirstOrDefault();
Its filled OK.
On this action i made my special validations. If catch any invalid data, i throw an exception.
This my catch part
catch (Exception ex)
{
var customerAttributesXml = ParseCustomCustomerAttributes(form);
model = _customerModelFactory.PrepareRegisterModel(model, true, customerAttributesXml);
ModelState.AddModelError("", ex.Message);
return View(model);
}
So i redirected to the form screen again with form datas, and i edited data and click save button again.
At this time value of MyCustomProperty is coming as null
model.CustomProperties["MyCustomProperty"] // value of this is coming null
Property is exist but value is null.
Where is the problem on my code? Or is there another way to do this.