Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing data from View to Controller (MVC 3)
    text
    copied!<p>I've a problem with my ASP.NET application when I try to pass a string from a view to a controller...</p> <p><em>My controller (needed method)</em></p> <pre><code>`public ActionResult Mail(int id) //Display the View "Mail" { Customer customer = db.Customers.Find(id); return View(customer); } [HttpPost,ActionName("Mail")] // this Method allow to send a email public ActionResult MailConfirmed(int id) { Customer customer = db.Customers.Find(id); string message = Request.Form.Get("messageBody");//Here I try to recuperate my messageBody if(message!=null) { System.Diagnostics.Debug.WriteLine(message); SendMail(customer.Mail, customer.Name, message); return RedirectToAction("Index"); } else { ModelState.AddModelError("", "Veuillez rentrer un message SVP"); } return View(customer); }` </code></pre> <p><em>View "Mail"</em> (Page where the manager can enter a message body and click on "mail" to send the message)</p> <pre><code>'@using (Html.BeginForm()) { &lt;fieldset&gt; &lt;legend&gt;Customer&lt;/legend&gt; &lt;div class="display-label"&gt;Pin&lt;/div&gt; &lt;div class="display-field"&gt; @Html.DisplayFor(model =&gt; model.Pin) &lt;/div&gt; &lt;div class="display-label"&gt;Name&lt;/div&gt; &lt;div class="display-field"&gt; @Html.DisplayFor(model =&gt; model.Name) &lt;/div&gt; etc... &lt;div class="display-field"&gt; @Html.TextBox("messageBody",null)//here the value that I try to pass in my controller &lt;/div&gt; &lt;/fieldset&gt; } @using (Html.BeginForm()) { &lt;p&gt; &lt;input type="submit" value="Mail" /&gt; &lt;div&gt; @Html.ActionLink("Back to List", "Index") &lt;/div&gt; &lt;/p&gt; }` </code></pre> <p><strong>the "message" is always null...Can you help me, please ?</strong></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload