Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 如何引用在Razor表达式中创建的控件?_Asp.net Mvc_Razor - Fatal编程技术网

Asp.net mvc 如何引用在Razor表达式中创建的控件?

Asp.net mvc 如何引用在Razor表达式中创建的控件?,asp.net-mvc,razor,Asp.net Mvc,Razor,我在MVC的视图文件中有以下代码。我正在尝试创建一个基本的搜索框函数。第一个控件是搜索框,第二个是我要执行搜索的ActionLink ActionLink的第三个参数需要是搜索框的值,这样它就可以将用户正在搜索的值传递到我的控制器中——但我看不到引用搜索框的方法 如何引用此ActionLink参数中的搜索框值 @使用(Html.BeginForm()) { 搜索名字和/或姓氏:@Html.TextBox(“搜索字符串”) @ActionLink(“搜索”、“搜索联系人”、“搜索字符串”);

我在MVC的视图文件中有以下代码。我正在尝试创建一个基本的搜索框函数。第一个控件是搜索框,第二个是我要执行搜索的ActionLink

ActionLink的第三个参数需要是搜索框的值,这样它就可以将用户正在搜索的值传递到我的控制器中——但我看不到引用搜索框的方法

如何引用此ActionLink参数中的搜索框值

@使用(Html.BeginForm())
{

搜索名字和/或姓氏:@Html.TextBox(“搜索字符串”)
@ActionLink(“搜索”、“搜索联系人”、“搜索字符串”);


}
要完全按照您的要求执行,您需要一些javascript,因为搜索框中的值是由用户输入的

但是,由于您有一个表单(
@使用(Html.BeginForm())
),您可以更改提交按钮的ActionLink,例如:

@using (Html.BeginForm("SearchContacts","YourController", FormMethod.Get))
{
    <p>
        Search First and/or Last Name: @Html.TextBox("SearchString") <br />
        <input type="submit" value="Search" />
    </p>
}
@使用(Html.BeginForm(“SearchContacts”、“YourController”、FormMethod.Get))
{

搜索名字和/或姓氏:@Html.TextBox(“搜索字符串”)

}
您需要使用javascript来响应客户端事件(并根据文本框中的值构建url,并使用
location.href
进行重定向)。感谢Romias,这非常有效!比使用ActionLink更好。