If you are trying to preserve null values as nulls and empty strings as empty strings for a round-trip operation, perhaps you could define a special constant string value to denote null. Perhaps something like this in a static class (so you can make an extension of it):
private const string NULL_STRING = "__@NULL@__";
public static string StringifyIfNull(this string s) {
return s == null ? NULL_STRING : s;
}
public static string DestringifyIfNull(this string s) {
return NULL_STRING == s ? null : s;
}
So, when setting the hidden string properties on your model, use hiddenString.StringifyIfNull()
, and when reading back the hidden values after a POST, use model.HiddenString.DestringifyIfNull()