title: Could not locate Razor Host Factory type (ASP.NET WEB MVC )
body: <p>I have been trying to solve this razor form error for a week now and I can't seem to fix it.</p>
  
  <p><strong>Packages</strong>:</p>
  
  <p>Microsoft.AspNet.MVC (version 5.2.4)</p>
  
  <p>M.AspNet.Razor (version 3.2.4)</p>
  
  <p>M.AspNet.WebPages (version 3.2.4)</p>
  
  <p>M.Web.Infrastructure (version 1.0.0.0)</p>
  
  <p>Newtonesoft.Json (version 11.0.2)</p>
  
  <p>System.Net.Http (version 4.3.3)</p>
  
  <p><a href="https://i.stack.imgur.com/LHRZn.png" rel="nofollow noreferrer">Packages Screenshot</a></p>
  
  <p>HomeController.cs (Code)</p>
  
  <pre><code>public async Task&lt;ActionResult&gt; Index()
      {
          PrimeCommand PCommand = new PrimeCommand();
  
          var responseString = await PCommand.Login("user", "pass", "api");
          ViewBag.SessionId = responseString;
  
          return View();
      }
  </code></pre>
  
  <p><strong>Login() function:</strong></p>
  
  <pre><code>public async Task&lt;string&gt; Login(string username, string password, string apikey)
      {
          try
          {
              using (var httpClientHandler = new HttpClientHandler())
              {
  
                  ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) =&gt; true; // PJDS code
                  using (var client = new HttpClient(httpClientHandler))
                  {
  
                      var newLogin = new LoginObject();
  
                      newLogin.ApplicationKey = apikey;
                      newLogin.UserName = username;
                      newLogin.Password = password;
  
                      var contentObject = JsonConvert.SerializeObject(newLogin);
                      var content = new StringContent(contentObject);
  
                      var response = await client.PostAsync(Api.base_url + "/Login", content);
                      var responseString = await response.Content.ReadAsStringAsync();
                      dynamic responseObject = JsonConvert.DeserializeObject(responseString);
  
                      var sessionID = responseObject.result.SessionID;
  
                      var searchObj = new SimpleSearchObject
                      {
                          SessionID = sessionID
                      };
  
                      return sessionID;
                  }
              }
          }
          catch (Exception e)
          {
              Debug.WriteLine("error: login - " + e.Message);
              return null;
          }
      }
  </code></pre>
  
  <p><strong>Index.cshtml</strong></p>
  
  <pre><code>&lt;form style="height: auto;width:300px;" action="action_page.php"&gt;
  &lt;div class="container"&gt;
          @using (Html.BeginForm())
  {
  
     &lt;b&gt;@Html.LabelFor(x =&gt; x.UserName)&lt;/b&gt;
      @Html.TextBoxFor(x =&gt; x.UserName)
      &lt;br /&gt;
  
      &lt;b&gt;@Html.LabelFor(x =&gt; x.Password)&lt;/b&gt;
      @Html.TextBoxFor(x =&gt; x.Password)
  
      &lt;button type="submit" value="Index" name="action:Index"&gt;Login&lt;/button&gt;
  
  
          &lt;label&gt;
              &lt;input type="checkbox" checked="checked" name="remember"&gt; Remember me
      &lt;/label&gt;
  }
  
      &lt;span class="psw"&gt;Forgot &lt;a href="#"&gt;password?&lt;/a&gt;&lt;/span&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>
  <strong>The Error</strong></p>
  
  <p>System.InvalidOperationException</p>
  
  <p>Could not locate Razor Host Factory type: 
  System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.0.0, Culture=neutral, PublicKeyToken=*******************</p>
  
  <p>Description: HTTP 500.Error processing request.</p>
  
  <p>Details: Non-web exception. Exception origin (name of application or object): System.Web.WebPages.Razor.</p>