1

So the presenter calls the model to get some data.

That data is returned as a DTO with no formatting.

Let's say the data is simply a decimal .12

Does the presenter then format the number to a percent?

view.Amount = Math.Round(dto.Amount * 100, 2) + "%";

Or is it the views responsibility?

public decimal Amount 
{
    set 
    {
        txtAmount.Text = Math.Round(dto.Amount * 100, 2) + "%";
    }
}
Lyubomyr Shaydariv
  • 20,327
  • 12
  • 64
  • 105
drizzie
  • 3,351
  • 2
  • 27
  • 32

2 Answers2

1

I do not use C# and WebFormsMvp, but I think your question is pretty much related to common MVP architecture. Let me explain it out of WebFormsMvp scope. The only responsiblity of a P should be mediating between a M and a V (in terms of how to "pass" the M data to the V and vice versa), and the V is responsible for how the data is represented to the user.

Consider the following scenario: you decide to drop the txtAmount field (let's consider it's just a text label or input, etc) in favor of a certain kind of progress bars or simple charts. If you passed "normalized" number values before (as they come from your M in your case) -- you still can replace your amount view as you wish, as they are supposed to accept a raw number value.

public interface IView {
    decimal Amount { set; }
}

Compare the above to:

public interface IView {
    // How to apply a string to a chart as a data item?
    string Amount { set; }
}

For the latter, you'd be face to face with "string to decimal" problem for the Amount property requiring to rework your string IView.Amount back to decimal IView.Amount (or even worse: parsing the percentaged value dropping the % sign and so on right in an IView instance to make it a number again even not knowing the original number type: was it a decimal or an integer?)

You might also consider percents as a V for humans: 42% in a percentage view or 420‰ in a promille view is still 0.42 in the model.

Lyubomyr Shaydariv
  • 20,327
  • 12
  • 64
  • 105
0

Theory about MVP says that Presenter does the formatting. In MVC theory says the View does the formatting.

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 30 '22 at 16:41