title: MVC ASP.NET No parameterless constructor defined for this object
body: <p>When I click submit in order to create an account the following error is displayed. I can't find why it is giving the following error. Also I tried to use breakpoints and debugging but it was useless</p>
  
  <blockquote>
    <p>No parameterless constructor defined for this object.</p>
    
    <p>Description: An unhandled exception occurred during the execution of
    the current web request. Please review the stack trace for more
    information about the error and where it originated in the code. </p>
    
    <p>Exception Details: System.MissingMethodException: No parameterless
    constructor defined for this object.</p>
    
    <p>Source Error: </p>
    
    <p>An unhandled exception was generated during the execution of the
    current web request. Information regarding the origin and location of
    the exception can be identified using the exception stack trace below.</p>
  </blockquote>
  
  <p><strong>AccountController.cs</strong></p>
  
  <pre><code>    [HandleError]
          public ActionResult CreateNewFixedBankAccount()
          {
              ViewBag.AccountFromList = new SelectList(
             ManageAccount.Instance.GetAccounts(), "accountID", "name");
              ViewBag.AccountTypes = new SelectList(ManageAccountType.Instance.GetNonFixedTypes(), "id", "type");
              ViewBag.Durations = new SelectList(ManageDuration.Instance.GetAllDurations(), "id", "duration1");
  
  
              ViewBag.Currencies = new SelectList(ManageCurrency.Instance.getCurrencies(), "id", "symbol");
              return View();
  
  
          }
  
          //
          // POST: /Account/CreateNewFixedBankAccount
          [HttpPost]
          [HandleError]
          public ActionResult CreateNewFixedBankAccount(ViewModel.NewAccountViewModel model, string username)
          {
  
              return View();
          }
  
  ___________________________________________________________________________________________
  </code></pre>
  
  <p><strong>CreateNewFixedBankAccount.cshtml</strong>
      The submit button below gives the error</p>
  
  <pre><code>    @model internetBankingApplication.ViewModel.NewFixedAccountViewModel    
      @{
          ViewBag.Title = "CreateNewFixedBankAccount";
      }
  
  
      @using (Html.BeginForm())
      {
  
          ViewBag.Title = "Create";
          Layout = "~/Views/Shared/_Layout.cshtml";
          &lt;fieldset&gt;
              &lt;legend&gt;Fixed Account Details&lt;/legend&gt;
  
              &lt;div class="editor-label"&gt;
              &lt;br /&gt;
       &lt;b&gt;@Html.LabelFor(model =&gt; model.Name)&lt;/b&gt;
              &lt;/div&gt;
              &lt;div class="editor-field"&gt;
                  @Html.EditorFor(model =&gt; model.Name)
              &lt;/div&gt;
  
              &lt;div class="editor-label"&gt;
              &lt;br /&gt;
                  &lt;b&gt; @Html.LabelFor(model =&gt; model.UserName)&lt;/b&gt;
              &lt;/div&gt;
              &lt;div class="editor-field"&gt;
                  @Html.EditorFor(model =&gt; model.UserName)
              &lt;/div&gt;
  
              &lt;div class="editor-label"&gt;
              &lt;br /&gt;
               &lt;b&gt; @Html.Label("Account From")&lt;/b&gt;
              &lt;/div&gt;
              &lt;div class="editor-field"&gt;
                   @Html.DropDownListFor(model =&gt; model.accountFrom, (SelectList)ViewBag.AccountFromList)
              &lt;/div&gt;
  
              &lt;div class="editor-label"&gt;
              &lt;br /&gt;
                 &lt;b&gt;  @Html.LabelFor(model =&gt; model.AvailableBalance)&lt;/b&gt;
              &lt;/div&gt;
              &lt;div class="editor-field"&gt;
                  @Html.EditorFor(model =&gt; model.AvailableBalance)
              &lt;/div&gt;
  
  
              &lt;div class="editor-label"&gt;
              &lt;br /&gt;
       &lt;b&gt;@Html.LabelFor(model =&gt; model.currency)&lt;/b&gt;
              &lt;/div&gt;
              &lt;div class="editor-field"&gt;
                   @Html.DropDownListFor(model =&gt; model.currency, (SelectList)ViewBag.Currencies)
              &lt;/div&gt;
  
              &lt;div class="editor-label"&gt;
              &lt;br /&gt;
                 &lt;b&gt;  @Html.LabelFor(model =&gt; model.Description)&lt;/b&gt;
              &lt;/div&gt;
              &lt;div class="editor-field"&gt;
                  @Html.EditorFor(model =&gt; model.Description)
              &lt;/div&gt;
  
              &lt;div class="editor-label"&gt;
              &lt;br /&gt;
                  &lt;b&gt; @Html.LabelFor(model =&gt; model.DateOpened)&lt;/b&gt;
              &lt;/div&gt;
              &lt;div class="editor-field"&gt;
                  @Html.EditorFor(model =&gt; model.DateOpened)
              &lt;/div&gt;
  
  
              &lt;div class="editor-label"&gt;
              &lt;br /&gt;
               &lt;b&gt; @Html.Label("Account Duration")&lt;/b&gt;
              &lt;/div&gt;
              &lt;div class="editor-field"&gt;
                   @Html.DropDownListFor(model =&gt; model.duration, (SelectList)ViewBag.Durations)
                   &amp;nbsp;
                    @Html.ActionLink("View Duration Details","DurationDetails","Duration")
              &lt;/div&gt;
  
  
              &lt;div class="editor-label"&gt;
              &lt;br /&gt;
               &lt;b&gt; @Html.Label("Account Renew")&lt;/b&gt;
              &lt;/div&gt;
              &lt;div class="editor-field"&gt;
                   @Html.CheckBoxFor(model =&gt; model.renew)
  
              &lt;/div&gt;
  
  
              &lt;p&gt;
                  &lt;input type="submit" value="CreateNewFixedBankAccount" /&gt;&lt;/p&gt;
          &lt;/fieldset&gt;
      }
  
  
  
  ___________________________________________________________________________________________
  </code></pre>
  
  <p><strong>NewFixedAccountViewModel.cs</strong></p>
  
  <p>This view model will get details that have to do with the account from different tables in the database.</p>
  
  <pre><code>    public class NewFixedAccountViewModel
      {
          private account _Account { get; set; }
  
          private fixedAccount _FixedAccount { get; set; }
  
          private int AccountFrom { get; set; }
  
          public SelectList AccountTypes { get; set; }
  
          public SelectList Durations { get; set; }
  
          public SelectList AccountFromList { get; set; }
  
          public SelectList Currencies { get; set; }
  
          public int ID
          {
              get
              {
                  return _Account.accountID;
              }
          }
  
          [Required]
          [Display(Name = "Account Name")]
          public string Name
          {
              get
              {
                  return _Account.name;
              }
              set
              {
                  _Account.name = value;
              }
          }
  
          [Required]
          [Display(Name = "Account From")]
          public int accountFrom
          {
              get
              {
                  return accountFrom;
              }
              set
              {
                  accountFrom = value;
              }
          }
  
          public string AccountFromName
          {
              get
              {
                  string result = string.Empty;
                  try
                  {
                      result = ManageAccount.Instance.GetAccountBYID(accountFrom).name;
                  }
                  catch { }
                  return result;
              }
          }
  
  
          [Required]
          [Display(Name = "Account Type")]
          public int typeID
          {
              get
              {
                  return _Account.typeID;
              }
              set
              {
                  _Account.typeID = value;
              }
          }
  
          public string AccountTypeName
          {
              get
              {
                  string result = string.Empty;
                  try
                  {
                      result = ManageAccountType.Instance.getTypesByID(_Account.typeID).type;
                  }
                  catch { }
                  return result;
              }
          }
  
  
          [Required]
          [Display(Name = "Duration")]
          public int duration
          {
              get
              {
                  return _FixedAccount.duration;
              }
              set
              {
                  _FixedAccount.duration = value;
              }
          }
  
          public string durationName
          {
              get
              {
                  string result = string.Empty;
                  try
                  {
                      result = ManageDuration.Instance.GetDurationById(_FixedAccount.duration).duration1;
                  }
                  catch { }
                  return result;
              }
          }
  
          [Required]
          [Display(Name = "Available Balance")]
          public decimal AvailableBalance
          {
              get
              {
                  return _Account.availableBalance;
              }
              set
              {
                  _Account.availableBalance = value;
              }
          }
  
          [Required]
          [Display(Name = "Currency")]
          public int currency
          {
              get
              {
                  return _Account.currency;
              }
              set
              {
                  _Account.currency = value;
              }
          }
  
          public string CurrencyName
          {
              get
              {
                  string result = string.Empty;
                  try
                  {
                      result = ManageCurrency.Instance.getTypesByID(_Account.currency).name;
                  }
                  catch { }
                  return result;
              }
          }
  
  
          [Required]
          [Display(Name = "Account Description")]
          public string Description
          {
              get
              {
                  return _Account.description;
              }
              set
              {
                  _Account.description = value;
              }
          }
  
  
          [Required]
          [Display(Name = "Account Renew")]
          public bool renew
          {
              get
              {
                  if (_FixedAccount.renew == 0)
                  {
                      return false;
                  }
                  return true;
              }
              set
              {
                  if (value == false)
                  {
                      _FixedAccount.renew = 0;
                  }
                  else
                  {
  
                      _FixedAccount.renew = 1;
                  }
              }
          }
  
  
          [Required]
          [Display(Name = "Date Opened")]
          public DateTime DateOpened
          {
              get
              {
                  return _Account.dateOpened;
              }
              set
              {
                  _Account.dateOpened = value;
              }
          }
  
          [Required]
          [Display(Name = "Username")]
          public string UserName
          {
              get
              {
                  return _Account.username;
              }
              set
              {
                  _Account.username = value;
              }
          }
  
          public NewFixedAccountViewModel(string username)
          {
              AccountTypes = new SelectList(
              ManageAccountType.Instance.getTypes(), "id", "type", _Account.typeID);
  
  
              AccountFromList = new SelectList(
              ManageAccount.Instance.GetUserAccounts(username), "accountID", "name", accountFrom);
  
              Currencies = new SelectList(
              ManageCurrency.Instance.getCurrencies(), "id", "name", _Account.currency);
  
              Durations = new SelectList(
              ManageDuration.Instance.GetAllDurations(), "id", "duration", _FixedAccount.duration);
  
  
          }
  
          public NewFixedAccountViewModel(int accountID, string username)
          {
              _Account = ManageAccount.Instance.GetAccountBYID(accountID);
  
              _FixedAccount = ManageFixedAccount.Instance.GetFixedAccountByID(accountID);
  
              AccountFromList = new SelectList(
              ManageAccount.Instance.GetUserAccounts(username), "accountID", "name", accountFrom);
  
              AccountTypes = new SelectList(
              ManageAccountType.Instance.getTypes(), "id", "type", _Account.accountType);
  
              Currencies = new SelectList(
              ManageCurrency.Instance.getCurrencies(), "id", "name", _Account.currency);
  
              Durations = new SelectList(
              ManageDuration.Instance.GetAllDurations(), "id", "duration", _FixedAccount.duration);
  
  
          }
  </code></pre>