Reputation: 29
I have simply view:
<input type="text" id="wprowadz" name="imie"/>
<input type="button" value="Create" onclick="location.href='@Url.Action("Wynik", "Home", new { name = name })'" />
And i need pass text from input to controller:
public string Wynik(string name)
{
return name;
}
i was search on tons of sites - i found this but it's not working - i got error on second "name" in view... what im doing wrong...
Upvotes: 1
Views: 1574
Reputation: 219127
You seem to be over-complicating this by involving JavaScript at all. If you just want an input, a button, and to post that value to the server then what you want is a form:
@using (Html.BeginForm("Wynik", "Home")
{
<input type="text" name="name" />
<input type="submit" value="Create" />
}
Upon clicking the "Create" button, the form is submitted to the Wynik
controller action with a string in the name
parameter.
Upvotes: 1