jason
jason

Reputation: 7164

Value cannot be null or empty - ASP.NET MVC 5

I have these fields in my View :

<dd>
    <a href="~/Docs/@Url.Content(Model.DocPath)">@Html.DisplayFor(model => model.DocPath)</a>
</dd>
<dd>
    <a href="~/Fonts/@Url.Content(Model.FontPath)">@Html.DisplayFor(model => model.FontPath)</a>
</dd>

When I upload something for Doc, but not for Font, then I open this View, I get Value cannot be null or empty error for this line :

<a href="~/Docs/@Url.Content(Model.DocPath)">@Html.DisplayFor(model => model.DocPath)</a>

Why am I getting the error for this line? This line is not null. And How can I make that View visible when the second url line is null? Thanks.

Upvotes: 0

Views: 718

Answers (1)

REDEVI_
REDEVI_

Reputation: 684

Yes as @Stephen Muecke said write an if else

if(Model.DocPath != null)
{
    <a href="~/Fonts/@Url.Content(Model.FontPath)">@Html.DisplayFor(model => model.FontPath)</a>   
}
else
{
<a href="~/Docs/@Url.Content(Model.DocPath)">@Html.DisplayFor(model => model.DocPath)</a>  
}

Upvotes: 1

Related Questions