One of the ways to send parameter via post to your controller
is by encapsulating its parameters within a form in CSHTML
of type POST
and sending them via submit.
You can use the helpers of MVC for this.
Example
In your Model:
public class PessoaModel
{
public string Nome {get;set;}
public string Senha {get;set;}
}
In your CSHTML View
@model PessoaModel
@using (Html.BeginForm("Salvar","PessoaController", FormMethod.POST))
{
@Html.Label("Nome"):
@Html.TextBoxFor(e => e.Nome) <br />
@Html.Label("Senha"):
@Html.TextBoxFor(e => e.Senha)
}
On your Controller
public class PessoaController : Controller
{
[HttpPost]
public ActionResult Salvar (PessoaModel model)
{
//Seu codigo quando a requisição post acontecer
}
}
You can also send POST
information through a form without the use of a model, using the helpers without the for termination, and having controller parameter of the same name passed in the helper parameter.
For example:
In your CSHTML:
@using (Html.BeginForm("Salvar","PessoaController", FormMethod.POST))
{
@Html.Label("Nome"):
@Html.TextBox("Nome") <br />
@Html.Label("Senha"):
@Html.TextBox("Senha")
}
On your Controller
public class PessoaController : Controller
{
[HttpPost]
public ActionResult Salvar(string nome, string senha)
{
//Seu codigo quando a requisição post acontecer
}
}