Last post Sep 19, 2019 01:47 AM by kvic
Sep 17, 2019 01:35 AM|kvic|LINK
I always have the issue of poorly formatted data for strings. I know there are many ways to do it but I only want it in one place
I would like to be able to do upper, camel, or lower case from the model as annotations or set it in the application Context to have SQL server do the work.
I looking for the cleanest and easiest way to do this when the user couldn't care less and types anyway they want and before it gets stored.
I'm wondering if there is a better way or just creating a class to perform this in the model|?
Sep 18, 2019 02:53 AM|Nan Yu|LINK
Hi kvic ,
One option is write custom model binding function which write your custom logic to format string . Below is one of the code sample :
Sep 19, 2019 01:47 AM|kvic|LINK
I have extended my model and now seeing upper and propercase being applied from the model.
One place to make all changes to the model seems to be the cleanest option
[Required(AllowEmptyStrings = false, ErrorMessage = "Company Name is Required.")]
[Display(Name = "Company Name", Description = "The Company Name.", Prompt = "Company Name", ShortName = "Company", Order = 1)]
public string CompanyName
CultureInfo cultureInfo = Thread.CurrentThread.CurrentCulture;
TextInfo textInfo = cultureInfo.TextInfo;
_companyName = CompanyName;
private string _ticker;
[Required(AllowEmptyStrings = false, ErrorMessage = "Company Ticker is Required.")]
[Display(Name = "Ticker", Description = "The Registered Company Ticker.", Prompt = "Company Ticker", ShortName = "Ticker", Order = 2)]
public string Ticker
_ticker = Ticker;
Still intersted in other ideas or to make mine better