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 如何将文本框中输入的值传递给操作方法_Asp.net Mvc_Asp.net Mvc 4 - Fatal编程技术网

Asp.net mvc 如何将文本框中输入的值传递给操作方法

Asp.net mvc 如何将文本框中输入的值传递给操作方法,asp.net-mvc,asp.net-mvc-4,Asp.net Mvc,Asp.net Mvc 4,我正在使用MVC构建一个电影应用程序。CRUD是VisualStudio自动为我创建的。现在,我正在尝试为用户构建一个搜索功能。以下是我编写的代码: @using (Html.BeginForm("SearchIndex", "Movies", new {searchString = ??? })) { <fieldset> <legend>Search</legend> <label>Title</

我正在使用MVC构建一个电影应用程序。CRUD是VisualStudio自动为我创建的。现在,我正在尝试为用户构建一个搜索功能。以下是我编写的代码:

@using (Html.BeginForm("SearchIndex", "Movies", new {searchString = ??? }))
{
    <fieldset>
        <legend>Search</legend>

        <label>Title</label>
        <input type ="text" id="srchTitle" />
        <br /><br />
        <input type ="submit" value="Search" />
    </fieldset>    
}
@使用(Html.BeginForm(“SearchIndex”,“Movies”,new{searchString=???}))
{
搜寻
标题


}
我已经构建了SearchIndex方法和相关视图。我就是找不到如何将文本框中输入的值传递给SearchIndex操作方法。
请提供帮助。

您需要为输入字段指定一个名称:

<input type="text" id="srchTitle" name="movieToFind" /> 

注意:表单字段名称必须与控制器中预期的参数匹配。或映射到模型属性(如果需要“模型”)

您需要为输入字段指定一个名称:

<input type="text" id="srchTitle" name="movieToFind" /> 

注意:表单字段名称必须与控制器中预期的参数匹配。或映射到模型属性(如果需要“模型”)

在您的模型中

public class Search
{
 public String SearchText { get; set; }
}
[HttpPost]
public ActionResult SearchIndex(Search model)
{
 String text = model.SearchText;
}
将视图设置为强类型,并使用

@Html.EditorFor(model => model.SearchText)
在您的控制器中

public class Search
{
 public String SearchText { get; set; }
}
[HttpPost]
public ActionResult SearchIndex(Search model)
{
 String text = model.SearchText;
}

希望这能有所帮助。

在您的型号中:

public class Search
{
 public String SearchText { get; set; }
}
[HttpPost]
public ActionResult SearchIndex(Search model)
{
 String text = model.SearchText;
}
将视图设置为强类型,并使用

@Html.EditorFor(model => model.SearchText)
在您的控制器中

public class Search
{
 public String SearchText { get; set; }
}
[HttpPost]
public ActionResult SearchIndex(Search model)
{
 String text = model.SearchText;
}
希望这有帮助