1.Concatenating strings

@(Model.address + " " + Model.city)

or

@(String.Format("{0} {1}", Model.address, Model.city))

With C# 6

@($"{Model.address} {Model.city}")

 

2.date to string
(1)Published若為not nullable
@item.Published.ToString("yyyy-MM-dd")

(2)Published若為nullable

@item.Published.Value.ToString("yyyy-MM-dd")

3.check string null/empty

@if (Model != null && !String.IsNullOrEmpty(Model.ImageName))
{
    <label for="Image">Change picture</label>
}

4.prevent escaping html in Razor

Html.Raw(Model.Content)

 

    全站熱搜

    smartfly 發表在 痞客邦 留言(0) 人氣()