A Better Razor IsNullOrEmpty Statement

Posted by: K. Scott Allen, on 28 Jun 2011 | View original | Bookmarked: 0 time(s)

This post is a play on Phil's "A Better Razor Foreach Loop". If you aren't familiar with templated delegates in Razor, you can follow the links in Phil's post. Something I don't like to see in a view is the if null or empty check. @if (!String.IsNullOrEmpty(User.Identity.Name)) { <span>Logged in as: @User.Identity.Name</span> } There are a number of ways to remove the check, but the knowledge in Phil's post give you one more option - the HTML helper option. public static class...

Advertisement
Free Agile Project Management Tool from Telerik
TeamPulse Community Edition helps your team effectively capture requirements, manage project plans, assign and track work, and most importantly, be continually connected with each other.
Category: ASP.NET | Other Posts: View all posts by this blogger | Report as irrelevant | View bloggers stats | Views: 519 | Hits: 73

Similar Posts

  • SQLite, ADO.NET, Prepared Statements, Transactions and Enterprise Manager more
  • Implement pagination using BETWEEN/AND more
  • Why I Love F#: Pattern Matching more
  • Find Top N costly query plans in adhoc batches or modules... more
  • OUTPUTing Data from the Just-Inserted, Updated, or Deleted Row(s) more
  • General SQL Parser .NET Component more
  • Find Top N costly query plans in adhoc batches or modules... more
  • Implement pagination using BETWEEN/AND more
  • TOP Clause Enhancements in SQL Server 2005 more

News Categories

.NET | Agile | Ajax | Architecture | ASP.NET | BizTalk | C# | Certification | Data | DataGrid | DataSet | Debugger | DotNetNuke | Events | GridView | IIS | Indigo | JavaScript | Mobile | Mono | Patterns and Practices | Performance | Podcast | Refactor | Regex | Security | Sharepoint | Silverlight | Smart Client Applications | Software | SQL | VB.NET | Visual Studio | W3 | WCF | WinFx | WPF | WSE | XAML | XLinq | XML | XSD