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

I want to know if it is possible to find out the value of html.textbox inside the view. if I have @ Html.TextBox ("textdata"), I can read data from this text field, as in my paragraph

my value: **

So I need this because I want this user to write a number inside the text field, which I will take as a parameter for my function, for example: @ Html.ActionLink ("click me", "actionname", "controller", new {param = textbox value}, "")

+3
source share
1 answer

For this you need to use javascript. Instead of using a link for actions, the best way to achieve this is to use a form:

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

, , , .

, javascript ( ), jQuery. URL:

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

All Articles