You can do it with ViewModels like how you passed data from your controller to view.
Assume 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 strongly typed to ReportViewModel
@model ReportViewModel
@using(Html.BeginForm())
{
Report NAme : @Html.TextBoxFor(s=>s.Name)
<input type="submit" value="Generate report" />
}
and in your HttpPost action method in your controller
[HttpPost]
public ActionResult Report(ReportViewModel model)
{
}
OR Simply, you can 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 same name as the textbox name.
[HttpPost]
public ActionResult Report(string reportName)
{
}
If you want to post to another controller, you may use this overload of the BeginForm method.
@using(Html.BeginForm("Report","SomeOtherControllerName"))
{
<input type="text" name="reportName" />
<input type="submit" />
}
Reference:
stackoverflow