title: Is this an MVC anti-pattern?
body: <p>I’m very new to any kind of .NET web development (thus far I’ve worked primarily with Winforms and services.) I’ve started to work on an existing MVC3 project with two other developers. I’m conceptually familiar with MVC, and am trying to catch up on how it’s used in this project.</p>
  
  <p>We have an AccountDto class to represent Accounts. There is a Response class that is inherited by another class for each Entity, i.e. AccountResponse:</p>
  
  <pre><code>public class Response
  {
      [DataMember]
      public bool IsSuccess{get;set;}
  
      [DataMember]
      public string DisplayMessage { get; set; }
  
      [DataMember]
      public string DetailedMessage { get; set; }
  
      [DataMember]
      public ErrorType ErrorType { get; set; }
  
      public Response(){
          this.IsSuccess=true;
          this.ErrorType = ErrorType.None;
      }
  }
  
  public partial class AccountResponse : Response
  {
      [DataMember]
      public IList&lt;AccountDto&gt; AccountList { get; set; }
  }
  </code></pre>
  
  <p>There’s an AccountService which will return an AccountResponse to the Controller, with a list of the AccountDto object:</p>
  
  <pre><code>public AccountResponse GetAccountByAccountId(Int64 accountId)
  {
      _logger.Info("Executing GetAccountByAccountId()");
      AccountResponse response = new AccountResponse();
  
      try
      {
          Account item = AccountPersistence.GetAccountByAccountId(accountId);
          AccountDto dto = Mapper.Map&lt;AccountDto&gt;(item);
  
          response.AccountList = new List&lt;AccountDto&gt;() { dto };
          response.IsSuccess = true;
      }
      catch (Exception ex)
      {
          response.IsSuccess = false;
          response.ErrorType = ErrorType.GeneralFault;
          response.DetailedMessage = ex.ExceptionMessageBuilder();
          response.DisplayMessage = "System Failure: Failed to get Account by AccountId";
          _logger.Error(ex);
      }
      return response;
  }
  </code></pre>
  
  <p>I was told the Response thing is implemented to be able to handle success/failure messages. So in a controller, there’s code like the following (doesn’t happen to do anything special if a failure):</p>
  
  <pre><code>public ActionResult ToBeCalled(int id)
  {
      AccountDto dto = null;
      var response = _accountService.GetAccountByAccountId(Convert.ToInt64(id));
      if (response.IsSuccess)
      {
          dto = response.AccountList[0];
          return View(dto);
      }
      return View(dto);
  }
  </code></pre>
  
  <p>This made sense to me though I wasn’t sure where the success/error messages were going to be utilized. However, they now want to switch from using the DTO in views to using the Response, so success/failure will have to be handled in the views:</p>
  
  <pre><code>public ActionResult ToBeCalled(int id)
  {
      var response = _accountService.GetAccountByAccountId(Convert.ToInt64(id));
      return View(response);
  }
  </code></pre>
  
  <p>This seems off to me – instead of coding against a DTO as the model, I have to do something like the following for each page:</p>
  
  <pre><code>@{
      if (Model.IsSuccess)
      {
          var account = Model.AccountList.FirstOrDefault();
  
          if (account != null)
          {
              @Html.HiddenFor(x =&gt; account.AccountNumber)
          }
  }
  </code></pre>
  
  <p>The controllers’ ActionResult / HttpPost methods then have to also parse the DTO from these Response objects. This seems like an anti-pattern to me; are approaches like this normal?</p>
  
  <p>Apologies if this is too lengthy, please migrate if it belongs on Code Review or another site.</p>