Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • pronto 61 posts 172 karma points
    Jun 03, 2013 @ 13:58
    pronto
    0

    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:

    @{
        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);
        }
    }

    Hopefully that makes senses.
  • Ian Black 54 posts 230 karma points
    Jun 04, 2013 @ 16:59
    Ian Black
    100

    Hi pronto,

    I think Request.Form stores it's values by name rather than ID so:

    <input type="text" name="test"/>

    should work for you.

    Cheers,
    Ian. 

Please Sign in or register to post replies

Write your reply to:

Draft