Asp.net mvc get value from Html.textbox()

asp.netasp.net-mvc-3razortextbox

I want to know is it possible to find out the value of html.textbox inside a view.
if i have @Html.TextBox("textdata") can I read data from that textbox like in my paragraph

my value is: **

So i need this becouse i want that user write a number inside a textbox which i will take as an param to my function like:
@Html.ActionLink("click me", "actionname", "controller", new { param = textbox value}, "")

Best Answer

You need to use javascript for this. Instead of using an action link a better way to achieve this would be to use a form:

@using (Html.BeginForm("actionname", "controller", FormMethod.Get))
{
    @Html.TextBox("textdata")
    <input type="submit" value="click me" />
}

This way the value entered by the user in the textbox will be automatically sent to the server when he submits the form.

If you still want to do this using javascript (not recommended) here's how you could proceed with jQuery. Subscribe for the click event of the link and fetch the value from the text field and append it to the url:

$(function() {
    $('#id_of_your_link').click(function() {
        var value = $('#textdata').val();
        $(this).attr('href', function() {
            return this.href += '?param=' + encodeURIComponent(value);
        });
    });
});