imdadhusen
imdadhusen

Reputation: 2494

How to use .trim().length in .cshtml page

I have written following condition in .cshtml page but it is not working

@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>
            }

My requirement is if FullName contains empty then link visible for Create else Edit. It is giving me following

Error:

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

if i use @if (row.item.FullName == "") then it will display following screen

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

Upvotes: 0

Views: 2825

Answers (2)

Andrew Cooper
Andrew Cooper

Reputation: 32596

Try this:

@if (String.IsNullOrEmpty(row.item.FullName))

Upvotes: 2

Simon Linder
Simon Linder

Reputation: 3448

Try String.IsNullOrEmpty(row.item.FullName).

Upvotes: 4

Related Questions