从Html.textbox(asp.net的MVC GET值) [英] asp.net mvc get value from Html.textbox()

查看:112
本文介绍了从Html.textbox(asp.net的MVC GET值)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道的是它可以找出html.textbox的视图中的价值。
如果我有@ Html.TextBox(的TextData),我可以在我的段落读起来就像从文本数据

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

我的值是:**

所以我需要这个becouse我想,写用户一个文本框,我将作为一个参数,以我之类的函数里面数:
@ Html.ActionLink(点击我,actionname,调节器,新的{参数=文本框的值},)

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}, "")

推荐答案

您需要使用JavaScript这一点。相反,使用操作链接一个更好的方式来实现,这将是使用表单:

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.

如果你仍然想这样做,使用JavaScript(不推荐),这里是你如何使用jQuery进行。订阅链接的点击事件并获取从文本字段中的值,并将其追加到网址:

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

这篇关于从Html.textbox(asp.net的MVC GET值)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆