I need to insert through @HTML.DisplayForwhen the support model value is null or empty.
@HTML.DisplayFor
I tried using data annotations
[DisplayFormat(ConvertEmptyStringToNull = true, NullDisplayText =" " ] public string MiddleName { get; set; }
which really works to stick to the "" where I expect this, but instead I need to put a non-expanding space.
This works for me:
NullDisplayText = @" ", HtmlEncode = false
Try something like:
var space = " "; [DisplayFormat(ConvertEmptyStringToNull = true, NullDisplayText ="@space" ] public string MiddleName { get; set; }
" " , #. , HTML- , .
" "
, @Html.DisplayFor. .
@Html.DisplayFor
@helper NonBreakingSpacesIfNullOrEmpty(string field, int spaces) { if (String.IsNullOrEmpty(field)) { @(new HtmlString(String.Concat(Enumerable.Repeat(" ", spaces)))) } else { @field } }
.
@FooHelper.NonBreakingSpacesIfNullOrEmpty(Model.MiddleName, 1)
spaces , .
spaces
Source: https://habr.com/ru/post/1527568/More articles:Disable two-factor authentication in ASP.NET Identity 2.0.0-beta1 - asp.netASP.Net Session Variables - Configure session variables and then redirect - asp.netminimum height and minimum width should always be equal - htmlHow to find the maximum number (number) in a list with anchored numbers - pythonIs it possible to use querySelectorAll for an array of elements? - javascriptTransaction ID not appearing in application to application - iosWhy do the results of the vector Clojure function exclude the stop value? - vectorDrupal considers ajax error - javascriptHow to fix 404 warnings with Karma for my AngularJS project? - angularjsHow do you determine the value of a return statement that is not stored in a variable? - c #All Articles