如何获取文本框的值在行动中asp.net MVC 5 [英] How to get textbox value in Action in asp.net MVC 5

查看:108
本文介绍了如何获取文本框的值在行动中asp.net MVC 5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要发送文本框操作方法的价值搜索技术,我想在行动文本框的值。

I want to send the value of textbox to the Action Method for searching the technology for that i want to get the value of textbox in Action.

我有以下的code: -

I have the following code :-

@Html.TextBox("technologyNameBox", "", new { id = "technologyName", @class = "form-control", @placeholder = "Search For Technology" })

<span class="input-group-btn" style="text-align:left">
      <a class="btn btn-default" id="searchTechnology" 
         href="@Url.Action("SearchTechnology", "Technology",
         new {technologyName="technologyName",projectId=ProjectId })">
           <span class="glyphicon glyphicon-search "></span>
      </a>
</span>

问题: - 如何在行动中得到的文本框technologyNameBox值

Question :- How to get the value of textbox "technologyNameBox" in Action ?

请帮助我。在此先感谢!

Please help me out. Thanks in Advance!

推荐答案

你必须指导用户之前附加价值,通过JavaScript的URL。使用jQuery(因为一般都自带ASP.NET封装),它可能看起来像这样(为空值或查询字符串参数手册条件检查好位):

You'd have to append the value to the URL via JavaScript before directing the user. Using jQuery (since that generally comes packaged with ASP.NET), it might look something like this (with a good bit of manual conditional checks for blank values or query string parameters):

$('#searchTechnology').click(function (e) {
    e.preventDefault();

    var url = '@Url.Action("SearchTechnology", "Technology", new { projectId=ProjectId })';
    var technologyName = $('#technologyName').val();

    if (technologyName.length < 1) {
        // no value was entered, don't modify the url
        window.location.href = url;
    } else {
        // a value was entered, add it to the url
        if (url.indexOf('?') >= 0) {
            // this is not the first query string parameter
            window.location.href = url + '&technologyName=' + technologyName;
        } else {
            // this is the first query string parameter
            window.location.href = url + '?technologyName=' + technologyName;
        }
    }

    return false;
});

的想法是,当用户点击该链接,你会获取在输入输入的值,并将其添加到URL作为查询字符串参数。然后将用户重定向到新的修改后的URL。

The idea is that when the user clicks that link, you would fetch the value entered in the input and append it to the URL as a query string parameter. Then redirect the user to the new modified URL.

这篇关于如何获取文本框的值在行动中asp.net MVC 5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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