title: MVC4 - How to call controller method from razor view
body: <p>i am new with MVC, can someone please help me and explain how to call controller method from a view. </p>
  
  <p>I have HomeController and inside it I have method ShowFileContent().</p>
  
  <pre><code>[HttpPost]
  public ActionResult ShowFileContent()
  {
      string filepath = Server.MapPath("\\Files\\Columns.txt");    
      try
      {
          var lines = System.IO.File.ReadAllLines(filepath);
  
          foreach (var line in lines)
          {
              ViewBag.FileContent += line + "\n";
  
          }
      }
      catch (Exception exc)
      {
          ViewBag.FileContent = "File not found";
      }
  
      return View();
  } 
  </code></pre>
  
  <p>Inside view I've tried to call this method with code bellow but it does not work.</p>
  
  <pre><code>@using (Html.BeginForm("ShowFileContent", "Home"))
  {
      &lt;input type="submit" value="Show File" style='width:300px'/&gt;        
  }
  &lt;h2&gt;@Html.Raw(ViewBag.FileContent.Replace("\n", "&lt;/br&gt;"))&lt;/h2&gt;
  </code></pre>
  
  <p>I get error: The view 'ShowFileContent' or its master was not found or no view engine supports the searched locations.</p>
  
  <p>What i am doing wrong and whats the best way to call methods from razor view ?</p>