制作一个搜索框,如果能将现有的搜索框实现为新样式,我感到非常好奇。
我有一个有效的搜索框,并在代码中对其进行了注释。我想在新的搜索框中添加Viewbag,但我可以找到一种方法
@using (Html.BeginForm())
{
<div class="input-group mb-3">
<input type="text" onfocus = "this.value=''" value="@(ViewBag.CurrentFilter)" class="form-control" placeholder="Search" aria-label="Recipient's username" aria-describedby="basic-addon2">
<div class="input-group-append">
<button class="btn btn-outline-secondary" type="submit">Button</button>
</div>
</div>
@*<div class="col-auto">*@
@*@Html.TextBox("Search", ViewBag.CurrentFilter as string, new { onfocus = "this.value=''", @class = "form-control", @id = "form-font", @placeholder = "Search", @style = "border-radius:0px", @autocomplete = "off" })*@
@*<button type="submit"><span class="fa fa-search"></span></button>*@
@*</div>*@
}
按钮正在工作,因为我在另一个搜索框上尝试过,但是当我在搜索框中键入文本时,单击搜索按钮没有任何反应
答案 0 :(得分:0)
对于Post
,您应该使用@using (Html.BeginForm("Index", "Home", FormMethod.Post))
,并将type="submit"
用于输入标签html。
@using (Html.BeginForm("Index", "Home", FormMethod.Post))
{
<div class="col-auto">
@Html.TextBox("Search", ViewBag.CurrentFilter as string, new { onfocus
= "this.value=''", @class = "form-control", @id = "form-font", @placeholder =
"Search", @style = "border-radius:0px", @autocomplete = "off" })
<input type="submit" /><span class="fa fa-search"></span>
</div>
}