lundi 23 novembre 2015

MVC: Should we have any if else OR other logical statement in View?

THIS IS MY MODEL:

public class Employee
{
    public string EmployeeName { get; set; }
    public string Address { get; set; }
    public DateTime DateOfBirth { get; set; }
    public int Salary { get; set; }
}

THIS IS MY VIEW:

<div>
    Employee Detail<br />
    Employee Name : @Model.emp.EmployeeName<br />
    Address : @Model.emp.Address <br />
    Age : @Model.Age
    <span style="color:@Model.SalaryColor">Salary : @Model.emp.Salary</span>
     @if (Model.Salary > 20000)
     {
         <div1>..</div1>
     }
     else
     {
        <div2>..</div2>
     }
</div>

With this if/else, i am inserting business logic in the UI Layer/ View of MVC. But i am clueless how can this be avoided?

I know that this would make UI tightly bound with Business logic which is not good. Any way i can avoid this?

Aucun commentaire:

Enregistrer un commentaire