I'm trying to create a Razor script wherein the user enters a value into a textbox, submits the form and the textbox value is appended to the page's Url in a query string. So for example, I type in "test" into the textbox, click submit and I'm on http://mysite.com?query=test.
Here's a snippet of my code - the variable "@test" is empty and I have no idea why:
@{
var test = ""; <form method="post"> <input type="text" id="test" /> <input type="submit" value="Submit" /> </form> if(IsPost){ test = Request.Form["test"]; Response.Redirect(@Model.Url + "?query=" + @test); } }
Append form value to Model Url
Hi everyone,
I'm trying to create a Razor script wherein the user enters a value into a textbox, submits the form and the textbox value is appended to the page's Url in a query string. So for example, I type in "test" into the textbox, click submit and I'm on http://mysite.com?query=test.
Here's a snippet of my code - the variable "@test" is empty and I have no idea why:
Hopefully that makes senses.
Hi pronto,
I think Request.Form stores it's values by name rather than ID so:
should work for you.
Cheers,
Ian.
is working on a reply...