title: "Value cannot be null or empty. Parameter name: contentPath" on a most unexpected line on postback when ModelState has errors
body: <p>It's been two hours straight I have been haggling with this monstrosity.</p>
  
  <p>I get this error:</p>
  
  <blockquote>
    <p>Value cannot be null or empty. Parameter name: contentPath</p>
  </blockquote>
  
  <p>On this line in my view:</p>
  
  <pre><code>@Html.ValidationMessageFor(model =&gt; model.IssueName, 
    "", new { @class = "text-danger" })
  </code></pre>
  
  <p>The stack trace given below seems to suggest that a call to <code>Url.Content</code> has been made, but I have made no such call. Below is the stack trace and that is followed by some more lines of code around the line which causes the error:</p>
  
  <blockquote>
    <p>[ArgumentException: Value cannot be null or empty. Parameter name:
    contentPath]    System.Web.Mvc.UrlHelper.GenerateContentUrl(String
    contentPath, HttpContextBase httpContext) +125<br>
    System.Web.Mvc.UrlHelper.Content(String contentPath) +26<br>
    ASP._Page_Views_Journal_EditIssue_cshtml.Execute() in
    MyProject\Views\Journal\EditIssue.cshtml:45<br>
    System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +197<br>
    System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +105<br>
    System.Web.WebPages.StartPage.RunPage() +17<br>
    System.Web.WebPages.StartPage.ExecutePageHierarchy() +64<br>
    System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext
    pageContext, TextWriter writer, WebPageRenderingBase startPage) +78<br>
    System.Web.Mvc.RazorView.RenderView(ViewContext viewContext,
    TextWriter writer, Object instance) +256<br>
    System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext
    viewContext, TextWriter writer) +107<br>
    System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
    +291    System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext
    controllerContext, ActionResult actionResult) +13<br>
    System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList<code>1
    filters, Int32 filterIndex, ResultExecutingContext preContext,
    ControllerContext controllerContext, ActionResult actionResult) +56<br>
    System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList</code>1
    filters, Int32 filterIndex, ResultExecutingContext preContext,
    ControllerContext controllerContext, ActionResult actionResult) +420<br>
    System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext
    controllerContext, IList<code>1 filters, ActionResult actionResult) +52<br>
    System.Web.Mvc.Async.&lt;&gt;c__DisplayClass2b.&lt;BeginInvokeAction&gt;b__1c()
    +173    System.Web.Mvc.Async.&lt;&gt;c__DisplayClass21.&lt;BeginInvokeAction&gt;b__1e(IAsyncResult
    asyncResult) +100<br>
    System.Web.Mvc.Async.WrappedAsyncResult</code>1.CallEndDelegate(IAsyncResult
    asyncResult) +10<br>
    System.Web.Mvc.Async.WrappedAsyncResultBase<code>1.End() +49<br>
    System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult
    asyncResult) +27<br>
    System.Web.Mvc.Controller.&lt;BeginExecuteCore&gt;b__1d(IAsyncResult
    asyncResult, ExecuteCoreState innerState) +13<br>
    System.Web.Mvc.Async.WrappedAsyncVoid</code>1.CallEndDelegate(IAsyncResult
    asyncResult) +29<br>
    System.Web.Mvc.Async.WrappedAsyncResultBase<code>1.End() +49<br>
    System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +36
    System.Web.Mvc.Controller.&lt;BeginExecute&gt;b__15(IAsyncResult
    asyncResult, Controller controller) +12<br>
    System.Web.Mvc.Async.WrappedAsyncVoid</code>1.CallEndDelegate(IAsyncResult
    asyncResult) +22<br>
    System.Web.Mvc.Async.WrappedAsyncResultBase<code>1.End() +49<br>
    System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +26<br>
    System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult
    asyncResult) +10<br>
    System.Web.Mvc.MvcHandler.&lt;BeginProcessRequest&gt;b__5(IAsyncResult
    asyncResult, ProcessRequestState innerState) +21<br>
    System.Web.Mvc.Async.WrappedAsyncVoid</code>1.CallEndDelegate(IAsyncResult
    asyncResult) +29<br>
    System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49<br>
    System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)
    +28    System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult
    result) +9<br>
    System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
    +9644097    System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously) +155</p>
  </blockquote>
  
  <p>The lines of code around the line that throws the exception are:</p>
  
  <pre><code>&lt;div class="form-group"&gt;
      @Html.LabelFor(model =&gt; model.IssueName, htmlAttributes: new { @class = "control-label col-md-2"})
      &lt;div class="col-md-10"&gt;
          @Html.EditorFor(model =&gt; model.IssueName, new { htmlAttributes = new { @class = "form-control", id = "IssueName" } })
          @Html.ValidationMessageFor(model =&gt; model.IssueName, "", new { @class = "text-danger" })
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>IMPORTANT</strong></p>
  
  <p>Strangely, the exception is raised only when I come back from a post-back and never when I first load the view, and not even when the <code>ModelState</code> has no errors. It only is raised when the <code>ModelState</code> has errors after a post-back.</p>
  
  <p>Here is some server side code, though I don't see any reason why it might be doing something wrong:</p>
  
  <pre><code>[HttpPost]
  public async Task&lt;ActionResult&gt; EditIssue(EditIssueViewModel viewModel)
  {
      viewModel.AvailableTags = BusinessManager.GetAllTags();
  
      if (viewModel.IssuePDFFile == null || viewModel.IssuePDFFile.ContentLength == 0)
      {
          ModelState.AddModelError("", "Please select a file to upload.");
          return View(viewModel);
      }
  
      var fileInfo = new FileInfo(viewModel.IssuePDFFile.FileName);
      if (!StaticData.AcceptedContentTypes.Contains(viewModel.IssuePDFFile.ContentType, StringComparer.InvariantCultureIgnoreCase) ||
          !fileInfo.Extension.Equals(".pdf", StringComparison.InvariantCultureIgnoreCase))
      {
          ModelState.AddModelError("", "You can only select a PDF file.");
          return View(viewModel);
      }
  
      if (!ModelState.IsValid)
      {
          var errors = ModelState.Values.SelectMany(v =&gt; v.Errors)
              .Select(e =&gt; new { e.ErrorMessage, e.Exception });
  
          var errorList = errors.ToList();
  
          errorList.ForEach(e =&gt; Debug.Print(e.ErrorMessage));
          errorList.ForEach(e =&gt; ModelState.AddModelError("", e.ErrorMessage));
  
          return View(viewModel);
      }
  
      var operationResult = await BusinessManager.EditIssueAsync(viewModel);
  
      if (!operationResult.Succeeded)
      {
          ModelState.AddModelError("", operationResult.FailureMessage);
          return View(viewModel);
      }
  
      viewModel = (EditIssueViewModel)BusinessManager.GetIssueWithRelationships(viewModel.IssueId);
      viewModel.SuccessMessage = operationResult.SuccessMessage;
      return View(viewModel);
  }
  </code></pre>