You can do this using ViewModels, for example, how you transferred data from your controller for viewing.
Suppose you have a viewmodel like this
public class ReportViewModel { public string Name { set;get;} }
and in your GET action,
public ActionResult Report() { return View(new ReportViewModel()); }
and your view must be strictly printed on ReportViewModel
@model ReportViewModel @using(Html.BeginForm()) { Report NAme : @Html.TextBoxFor(s=>s.Name) <input type="submit" value="Generate report" /> }
and in your HttpPost method in your controller
[HttpPost] public ActionResult Report(ReportViewModel model) {
OR You can simply do this without the POCO classes (Viewmodels)
@using(Html.BeginForm()) { <input type="text" name="reportName" /> <input type="submit" /> }
and in your HttpPost action use a parameter with the same name as the text field name.
[HttpPost] public ActionResult Report(string reportName) {
EDIT: According to the comment
If you want to send a message to another controller, you can use this overload of the BeginForm method.
@using(Html.BeginForm("Report","SomeOtherControllerName")) { <input type="text" name="reportName" /> <input type="submit" /> }
Passing data from an action method to view?
You can use the same view model, just set property values to your GET action method
public ActionResult Report() { var vm = new ReportViewModel(); vm.Name="SuperManReport"; return View(vm); }
and in your opinion
@model ReportViewModel <h2>@Model.Name</h2> <p>Can have input field with value set in action method</p> @using(Html.BeginForm()) { @Html.TextBoxFor(s=>s.Name) <input type="submit" /> }