title: Passing along data from Razor Form Post to F# controller
body: <p>How is it possible to pass along data using Razor in a F# MVC5 web application.</p>
  
  <p>For instance, in the view below when the <em>PostEmail</em> form is posting how can I pass along the value of the <em>newEmail</em> input as well as some fields from <em>ViewData</em>?</p>
  
  <p>And for the <em>DeleteEmail</em> form, how can I get the selected option value from the <em>emails</em> select?</p>
  
  <p>My View: (Settings.cshtml)</p>
  
  <pre><code>&lt;div style="width: 100%;"&gt;
      &lt;h2 id="title" style="margin: 0 auto;"&gt;@ViewBag.PageTitle&lt;/h2&gt; &lt;br&gt; &lt;br&gt;
      &lt;div style="width: 60%; margin: 0 auto;"&gt;
          &lt;div style="float: left; clear: none; width: 45%;"&gt;
              &lt;span&gt;EMAILS&lt;/span&gt; &lt;br&gt;
  
              @using (Html.BeginForm("DeleteEmail", "QualityScore", FormMethod.Post))
              {
                  &lt;select id="emails" size="10" style="width: 100%; max-width: 100%"&gt;
                      @foreach (string email in ViewBag.EmailList)
                      {
                          &lt;option value="@email"&gt;@email&lt;/option&gt;
                      }
                  &lt;/select&gt;
                  &lt;input type="submit" id=" email_delete" value="Delete" /&gt;
              }
  
              @using (Html.BeginForm("PostEmail", "QualityScore", FormMethod.Post))
              {
                  &lt;input id="newEmail" /&gt;
                  &lt;input type="submit" id="email_create" value="Create" /&gt;
              }
  
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>My Controller: (QualityScoreController.fs)</p>
  
  <pre><code>type QualityScoreController(queries : DataQueries) =
      inherit Controller()
      new () = new QualityScoreController(DataQueries())
  
      member this.Settings(token) = 
          let db = DataConnection.GetDataContext()
  
          let user = queries.FindUserByToken(token, db)
  
          this.ViewData.Add("PageTitle", "Your QualityScore Report Settings")
          this.ViewData.Add("EmailList", queries.FindUsersReportEmails(user.Id, db))
          this.ViewData.Add("KeywordList", queries.FindUsersReportBrands(user.Id, db))
          this.ViewData.Add("UserID", user.Id)
  
          this.View()
  
      member this.PostEmail() =
          ... //need to use information sent from the form
  
      member this.DeleteEmail() =
          ... //need to use information sent from the form
  </code></pre>
  
  <hr>
  
  <p>MY SOLUTION</p>
  
  <p>My View: (Settings.cshtml)</p>
  
  <pre><code>&lt;div style="width: 100%;"&gt;
      &lt;h2 id="title" style="margin: 0 auto;"&gt;@ViewBag.PageTitle&lt;/h2&gt; &lt;br&gt; &lt;br&gt;
      &lt;div style="width: 60%; margin: 0 auto;"&gt;
          &lt;div style="float: left; clear: none; width: 45%;"&gt;
              &lt;span&gt;EMAILS&lt;/span&gt; &lt;br&gt;
  
              @using (Html.BeginForm("DeleteEmail", "QualityScore", FormMethod.Post))
              {
                  &lt;select name="emails" size="10" style="width: 100%; max-width: 100%"&gt;
                      @foreach (string email in ViewBag.EmailList)
                      {
                          &lt;option value="@email"&gt;@email&lt;/option&gt;
                      }
                  &lt;/select&gt;
                  &lt;input type="submit" id=" email_delete" value="Delete" /&gt;
                  &lt;input name="userid" none value="@ViewBag.UserID" /&gt;
              }
  
              @using (Html.BeginForm("PostEmail", "QualityScore", FormMethod.Post))
              {
                  &lt;input name="newEmail" /&gt;
                  &lt;input type="submit" id="email_create" value="Create" /&gt;
                  &lt;input name="userid" none value="@ViewBag.UserID" /&gt;
              }
  
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>My Controller: (QualityScoreController.fs)</p>
  
  <pre><code>type QualityScoreController(queries : DataQueries) =
      inherit Controller()
      new () = new QualityScoreController(DataQueries())
  
      member this.Settings(token) = 
          let db = DataConnection.GetDataContext()
  
          let user = queries.FindUserByToken(token, db)
  
          this.ViewData.Add("PageTitle", "Your QualityScore Report Settings")
          this.ViewData.Add("EmailList", queries.FindUsersReportEmails(user.Id, db))
          this.ViewData.Add("KeywordList", queries.FindUsersReportBrands(user.Id, db))
          this.ViewData.Add("UserID", user.Id)
  
          this.View()
  
      member this.PostEmail(newEmail: string,  userid : int) =
          ...
  
      member this.DeleteEmail(emails : string,  userid : int) =
          ...
  </code></pre>