How to move logical logic from my view?

In my ASP.NET MVC view, I select a sprite based on the boolean value specified in the model as follows:

<div class="sprite-icon_dog<% =(Model.HasNewDog ? "_new" : "") %>"></div>

It's ugly, and I don't like it.

My goal is to use sprite-icon_dog_newif Model.HasNewDogis trueand use sprite-icon_dogif Model.HasNewDogis false.

What is more elegant and understandable for this?

+3
source share
2 answers

I think an HTML helper would be the way to go?

public static string DogDiv(this HTMLHelper html, bool HasDog)
{
  return "...."
}

In your opinion:

<%=Html.DogDiv(Model.HasDog) %>

Hope this helps,

Dan

+5
source

, . html-, -. css, , , -.

, MVC. MVC , - , , , MVC.

0

Source: https://habr.com/ru/post/1716327/


All Articles