title: Passing Model data from View to Controller and using its values
body: <p>I'm trying to send data from the view and use it in the controller to construct a filename for an upload file feature I am working on, my code is below.</p>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>    // GET: File
      [Authorize(Roles = "Admin, Lecturer")]
      public ActionResult Index()
      {
  
  
  
          foreach (string upload in Request.Files)
          {
              if (Request.Files[upload].FileName != "")
              {
                  string path = AppDomain.CurrentDomain.BaseDirectory + "/App_Data/uploads/";
                  string filename = Path.GetFileName(Request.Files[upload].FileName);
                  Request.Files[upload].SaveAs(Path.Combine(path, filename));
              }
          }
          return View();
      }
  </code></pre>
  
  <p><strong>Model</strong></p>
  
  <pre><code>public class UploadModel
  {
      [Required(ErrorMessage = "Course is required")]
      public string Course { get; set; }
      [Required(ErrorMessage = "Title is required")]
      public string Title { get; set; }
  
      public string Uploader { get; set; }
  }
  </code></pre>
  
  <p><strong>View</strong> </p>
  
  <pre><code>&lt;div class="uploadContainer"&gt;
      &lt;table&gt;
  
  
          &lt;tr&gt;
              &lt;td&gt;Title :&lt;/td&gt;
              &lt;td colspan="2" class="editPostTitle"&gt;
                  @Html.TextBoxFor(tuple =&gt; tuple.Item1.Title, new { @class = "uploadTitleInp" })
                  @Html.ValidationMessageFor(tuple =&gt; tuple.Item1.Title)
              &lt;/td&gt;
          &lt;/tr&gt;
  
          &lt;tr&gt;
              &lt;td&gt;Course :&lt;/td&gt;
              &lt;td&gt;
                  @{
                      List&lt;SelectListItem&gt; listItems = new List&lt;SelectListItem&gt;();
                      foreach (var cat in courses)
                      {
                          listItems.Add(new SelectListItem
                          {
                              Text = cat.Course.Name,
                              Value = cat.Course.Name
                          });
                      }
                  }
  
                  @Html.DropDownListFor(tuple =&gt; tuple.Item1.Course, listItems, "-- Select Status --")
  
                  @Html.ValidationMessageFor(tuple =&gt; tuple.Item1.Course)
              &lt;/td&gt;
          &lt;/tr&gt;
  
          &lt;tr&gt;
              &lt;td&gt;File :&lt;/td&gt;
              &lt;td&gt;
                  &lt;input type="file" name="FileUpload1" id="fileUpload" required /&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
  
          &lt;tr&gt;
              &lt;td&gt;&lt;/td&gt;
              &lt;td&gt;
                  &lt;input id="btnUploadFile" type="button" value="Upload File" /&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
  
      &lt;/table&gt;
  
  &lt;/div&gt;
  </code></pre>
  
  <p>This method is responsible for placing the file that is uploaded into the directory. What I want to be able to do is create a file name by doing something like this.</p>
  
  <pre><code>string filename = model.Title + " - " + model.Course;
  </code></pre>
  
  <p>I usually know how to achieve this when using a db to store data but since I am not storing the files that are uploaded in a db then I don't really know how to pass the model data to the controller so I can use the values that have been entered by the user to construct the file name. I am relatively new to this framework and languages so any help and pointers would be greatly appriciated.</p>
  
  <p>Thanks In advance!</p>