Reputation: 79
My controller :
[HttpPost]
public void setInfoUser(string str)
{
Demandeur demandeur = new Demandeur(str);
}
My view :
@using (Html.BeginForm("setInfoUser", "Personne", FormMethod.Post))
{
<input type="text" id="idUser" value="test" />
<input type="submit" value="ok" name="setInfoUser" />
}
The method is fired but the string is always null. What am I doing wrong?
Upvotes: 0
Views: 73
Reputation: 1305
You should use model based approach since you are using mvc
View:
@model Your_NameSpace.Demandeur
@using (Html.BeginForm("setInfoUser", "Personne", FormMethod.Post))
{
@Html.EditorFor(model=>model.UserName)
<input type="submit" value="ok" name="setInfoUser" />
}
Controller
[HttpPost]
public void setInfoUser(Demandeur demandeur)
{
//your logic ahead
}
Upvotes: 0
Reputation: 1058
Set name attribute to be equal to your string variable.
<input type="text" id="idUser" name="str" value="test" />
Upvotes: 2