title: file upload in asp.net mvc 4 razor
body: <p>I am using <strong>ASP .Net MVC 4.0</strong> and <strong>VS10</strong>. I am a newbie in web application. </p>
  
  <p>I have designed a page with html razor view. Here is some code of <strong>Index.cshtml</strong>:</p>
  
  <pre><code>@{
  ViewBag.Title = "BAP Automation";
  }
  @section featured {
      &lt;section class="featured"&gt;
          &lt;div class="content-wrapper"&gt;
              &lt;hgroup class="title"&gt;
                  &lt;h1&gt;@ViewBag.Title.&lt;/h1&gt;
                  &lt;h2&gt;@ViewBag.Message&lt;/h2&gt;
              &lt;/hgroup&gt;
              &lt;form action="Index"&gt;
              &lt;table&gt;              **//EDITED BELLOW**
                  &lt;tr&gt;&lt;form action="" method="post"&gt;
                      &lt;td&gt;Upload Excel File: &lt;/td&gt;
                      &lt;td&gt;&lt;input type="text" name="NAMEtxtFileName"/&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;input type="button" value="Upload" id="IDbtnUpload" name="NAMEbtnUpload"/&gt;&lt;/td&gt;
                      &lt;/form&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;Company Name: &lt;/td&gt;
                      &lt;td&gt;&lt;input type="text" /&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;&lt;/td&gt;
                      &lt;td align="right"&gt;&lt;input type="submit" value="Process" /&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;/td&gt;
                  &lt;/tr&gt;
              &lt;/table&gt;
              &lt;/form&gt;
          &lt;/div&gt;
      &lt;/section&gt;
  }
  </code></pre>
  
  <p>I am trying to upload an excel file in <strong>NAMEbtnUpload</strong>'s click event. clicking on this button we will be in this page, just a file upload dialog will open and selecting the file, the file location will be shown in the <strong>NAMEtxtFileName</strong> textbox.</p>
  
  <p><strong>EDIT 1:</strong></p>
  
  <p>I have written some code from the suggested code:</p>
  
  <pre><code>    [HttpPost]
      public ActionResult Index(HttpPostedFileBase NAMEbtnUpload)
      {
          if (NAMEbtnUpload.ContentLength &gt; 0)
          {
              var fileName = Path.GetFileName(NAMEbtnUpload.FileName);
              var path = Path.Combine(Server.MapPath("~/App_Data/Given Excel's"), fileName);
              NAMEbtnUpload.SaveAs(path);
          }
  
          return RedirectToAction("Index");
      }
  </code></pre>
  
  <p>but this shows following error:</p>
  
  <h2>    Server Error in '/' Application.</h2>
  
  <p><strong>The resource cannot be found.</strong> 
  <strong>Description</strong>: <strong>HTTP 404</strong>. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly. </p>
  
  <p><strong>Requested URL:</strong> /</p>