Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ASP.NET MVC Razor: Ternary
- @(string.IsNullOrEmpty(Model.Prop) ? "null" : "'" + Model.Prop + "'")
- public class Test {
- public string First { get; set; }
- public string Last { get; set; }
- }
- public class Test {
- [Display(Name = "First Name")]
- [DisplayFormat(DataFormatString = "'{0}'", NullDisplayText = "'null'")]
- public string First { get; set; }
- [Display(Name = "Last Name")]
- [DisplayFormat(DataFormatString = "'{0}'", NullDisplayText = "'null'")]
- public string Last { get; set; }
- }
- @Html.DisplayFor(model => model.First)
- @Html.DisplayFor(model => model.Last)
- [DisplayFormat(DataFormatString = "'{0}'", NullDisplayText = "null")]
- public class MyViewModel
- {
- [DisplayFormat(NullDisplayText = "null", DataFormatString = "'{0}'"]
- public string MyProperty { get; set; }
- }
- @model MyViewModel
- ...
- @Html.DisplayFor(x => x.MyProperty)
Add Comment
Please, Sign In to add comment