2016-05-01 84 views
1

所以我在ASP.NET webforms中實現MVP。在MVP中查看邏輯的位置?

我需要能夠根據某些數據的狀態更改標籤的顏色。

我第一次嘗試:

class Presenter 
{ 
    ... 
    _view.IsStatusTrue = true; 
} 

class View 
{ 
    bool IsStatusTrue 
    { 
     set 
     { 
      if(value) 
      { 
       lbl.Text = "Status is true :)"; 
       lbl.CssClass = "trueClass"; 
      } 
     } 
    } 
} 

我的問題:這樣的邏輯應該是在演示?

class Presenter 
{ 
    ... 
    if(status == true) 
    { 
     _view.LblCssClass = "trueClass"; 
     _view.StatusText = "Status is true :)"; 
    } 
} 

回答

0
public class Presenter 
{ 
    bool _status; 
    IView _view; 

    public Presenter(IView view) 
    { 
     _view = view; 

     if (_status) 
     { 
      _view.LabelColorCode = "#c2d8ff"; 
      _view.LabelText = "Status is true"; 
     } 
    } 
} 

public interface IView 
{ 
    string LabelColorCode { set; } 
    string LabelText { set; } 
}