asp.net-mvc-3
  • razor
  • 2011-08-02 32 views 0 likes 
    0

    我已經寫了在以下頁面.cshtml條件,但它不工作如何使用.trim()。長度

    @if (row.item.FullName.Trim().length <= 0) 
          { 
           @Html.ActionLink("Create", "Create", "UsersInfo") 
          } 
          else 
          { 
           <a href='@Url.Action("Edit", "UsersInfo", new { id = row.item.UserId }))'>Contact</a> 
          } 
    

    我的要求是,如果FullName包含空然後創建其他鏈接可見編輯。這是給我下面

    錯誤:

    System.NullReferenceException: Object reference not set to an instance of an object.

    如果我使用@if (row.item.FullName == "")然後它會顯示以下屏幕

    <img src='http://www.codeproject.com/script/Membership/Uploads/5038017/screen.png'/> 
    

    回答

    4

    嘗試String.IsNullOrEmpty(row.item.FullName)

    +0

    優秀的解決方案! – imdadhusen

    2

    試試這個:

    @if (String.IsNullOrEmpty(row.item.FullName)) 
    
    相關問題