One of the ways to send parameter via post to your controller
is encapsulating your parameters within a form in the CSHTML
of the kind POST
and sending them through Submit.
You can use the helpers of MVC for this.
Example
In his 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)
}
In your Controller
public class PessoaController : Controller
{
[HttpPost]
public ActionResult Salvar (PessoaModel model)
{
//Seu codigo quando a requisição post acontecer
}
}
You can also send information POST
using a form without the use of a model, using the helpers without the termination is, and having in its controller parameter of the same name passed in the helper.
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")
}
In your Controller
public class PessoaController : Controller
{
[HttpPost]
public ActionResult Salvar(string nome, string senha)
{
//Seu codigo quando a requisição post acontecer
}
}
you have everything inside a form?
– CesarMiguel
Post the relevant snippets of your code.
– Fernando Leal