开发者

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

开发者 https://www.devze.com 2023-03-25 11:12 出处:网络
I have written following condition in .cshtml page but it is not working @if (row.item.FullName.Trim().length <= 0)

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

@if (row.item.FullName.Trim().length <= 0)
    开发者_如何学JAVA        {
                @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'/>


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


Try this:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号