[英]How I can use html tags with bootstrap in asp.net mvc for get a result from controller?
Hey Guys I have a problem with my ASP.NET MVC Application. 嗨,我的ASP.NET MVC应用程序有问题。 I want to make a Search textfield and a image button in my application.
我想在我的应用程序中创建一个搜索文本字段和一个图像按钮。 If I input a valu in the textfield I want use this value for search in a list and send the result to the View.
如果我在文本字段中输入一个值,则要在列表中使用该值进行搜索并将结果发送到视图。 I use bootstrap because it looks fine.
我使用引导程序,因为它看起来不错。
here is my code: Index.cshtml 这是我的代码:Index.cshtml
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
@using (Html.BeginForm("Search", "HomeController"))
{
<div class="container">
<div class="row">
<h2>Suche</h2>
<div id="custom-search-input">
<div class="input-group col-md-12">
<input type="text" id="txtSearch" class=" search-query form-control" placeholder="Search" name="txtSearch" />
<span class="input-group-btn">
<button class="btn btn-danger" type="submit">
<span class=" glyphicon glyphicon-search"></span>
</button>
</span>
</div>
</div>
</div>
</div>
}
Here is my Controller: 这是我的控制器:
[HttpPost]
public ActionResult Search(string txt)
{
List<string> petList = new List<string>();
petList.Add(txt);
ViewBag.liste = petList;
return View();
}
Your input does not have a name
attribute that matches the parameter in the method so it is not bound. 您输入的
name
属性与方法中的参数不匹配,因此未绑定。 Change it to 更改为
<input type="text" id="txtSearch" class="..." name="txt" />
or change the method to match the current name
attribute 或更改方法以匹配当前
name
属性
[HttpPost]
public ActionResult Search(string txtSearch)
Side note: Assuming your controller is named HomeController
then it should be @using (Html.BeginForm("Search", "Home"))
, not @using (Html.BeginForm("Search", "HomeController"))
(which would only work if you have a controller named HomeControllerController
) 旁注:假设您的控制器名为
HomeController
那么它应该是@using (Html.BeginForm("Search", "Home"))
,而不是@using (Html.BeginForm("Search", "HomeController"))
(仅当您有一个名为HomeControllerController
的控制器时才有效)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.