title: Unable to access properties of model (vs Model)?
body: <p>Currently I have a view which takes an IEnumerable model which I use to display data on the view.  However on the same view I also have a modal popup in which I want to add to the model rather than separating them out into different views.  I tried to follow the suggestion at the bottom of this question <a href="https://stackoverflow.com/questions/8652082/how-to-access-model-property-in-razor-view-of-ienumerable-type">How to access model property in Razor view of IEnumerable Type?</a> but got an exception </p>
  
  <blockquote>
    <p>The expression compiler was unable to evaluate the indexer expression '(model.Count - 1)' because it references the model parameter 'model' which is unavailable.</p>
  </blockquote>
  
  <p>At the top of the view I have</p>
  
  <pre><code>@model IList&lt;Test.Models.DashModel&gt;
  </code></pre>
  
  <p>and within my modal body I have</p>
  
  <pre><code> @using (Html.BeginForm())
  {
      @Html.AntiForgeryToken()
  
      &lt;div class="form-horizontal"&gt;
          &lt;h4&gt;DashboardModel&lt;/h4&gt;
          &lt;hr /&gt;
          @Html.ValidationSummary(true, "", new { @class = "text-danger" })
          &lt;div class="form-group"&gt;
              @Html.LabelFor(model =&gt; model[model.Count - 1].DashName, htmlAttributes: new { @class = "control-label col-md-2" })
              &lt;div class="col-md-10"&gt;
                  @Html.EditorFor(model =&gt; model[model.Count - 1].DashName, new { htmlAttributes = new { @class = "form-control" } })
                  @Html.ValidationMessageFor(model =&gt; model[model.Count - 1].DashName, "", new { @class = "text-danger" })
              &lt;/div&gt;
          &lt;/div&gt;
  
          &lt;div class="form-group"&gt;
              @Html.LabelFor(model =&gt; model[model.Count - 1].CreatedDate, htmlAttributes: new { @class = "control-label col-md-2" })
              &lt;div class="col-md-10"&gt;
                  @Html.EditorFor(model =&gt; model[model.Count - 1].CreatedDate, new { htmlAttributes = new { @class = "form-control" } })
                  @Html.ValidationMessageFor(model =&gt; model[model.Count - 1].CreatedDate, "", new { @class = "text-danger" })
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  }
  </code></pre>