Conditionally showing span in ASP.Net MVC
I have the following..
<span class="error">@Model.ErrorMessage</span>
The problem is that the css for error class makes a yellow box which is showing up even when the ErrorMessage is empty.
Is there a best practice for handling this? I was thinking of an @If (using Razor) but it seems odd to ha开发者_JS百科ve logic like that in my view.
it seems odd to have logic like that in my view.
View will have view logic in it. MVC is not MVP or MVVM where any code behind is discouraged. I believe having if
in the view is quite normal.
Alternative is to have the model (view model) have a property which will be set as CSS class of the span
. If error is empty, CSS class could have display:none;
精彩评论