如何从控制器访问搜索输入类型=在mvc4中搜索

时间:2013-11-01 08:00:41

标签: .net asp.net-mvc-4

如何从控制器访问搜索输入类型=在mvc4中搜索。 这是我的视图cshtml代码。

我的代码:

<input name="searchValue" id="searchinput1" type="search" data-mini="true" data-align="left"/>

我的搜索内置了一个按钮,想要在控制器中访问。尝试过互联网的可能性,但无法找到更好的解决方案。 我不想单独使用按钮和文本框,而是使用此类型=搜索本身。

Search image

我希望通过点击搜索框内搜索左侧的按钮来实现搜索功能。

2 个答案:

答案 0 :(得分:1)

type="search"无法自动绑定到您的操作。它几乎就像一个普通的文本框<input type="text">,但是浏览器(现在的chrome和safari)可能会略微调整它以使其更可爱。如果不需要旁边的按钮,你必须手动挂钩事件(onkeydown()可能)。

答案 1 :(得分:0)

将其放在您的视图中

@using (Html.BeginForm("Search", "Home", FormMethod.Get))
           {@Html.TextBox("name", null, new { id = "SearchBox", @class = "SearchBox" })}

在您的控制器中添加以下代码

public ActionResult Search(string name)
    {
        //do anything with the name
}

您将能够访问控制器中的文本框

相关问题