我有一个控制器3个actionResults,我希望所有actionResults返回一个视图作为代码如下:试图调用视图错误的操作方法的结果
在控制器:
public ActionResult Index()
{
return View(ListGroup);
}
[HttpPost]
public ActionResult Index(List<Group> listModel) {
@ViewBag.Success = "Update Suceess";
return View(listModel);//I set break point here
}
[HttpPost]
public ActionResult Search(Group ModelSearch) {
List<Group> listResult = ListGroup.Where(m=>m.GroupID == ModelSearch.GroupID).ToList();
return View("Index", listResult);
}
鉴于我有两种形式:
@using (Html.BeginForm("Search", "DisplayTable"))
{
<fieldset>
<legend>Search</legend>
<input type="text" name="GroupID" />
<input type="submit" value="SEARCH" />
</fieldset>
}
@using (Html.BeginForm("Index", "DisplayTable", FormMethod.Post))
{
var i = 0;
<table>
<tr>
<td>Name</td>
<td>GroupID</td>
</tr>
@foreach(var item in Model){
<tr>
<td>@Html.TextBoxFor(m => m[i].Name)</td>
<td>@Html.TextBoxFor(m => m[i].GroupID)</td>
</tr>
i++;
}
</table>
<input type="submit" value="SAVE" />
}
有两两件事我想这个控制器做:
根据输入搜索记录库。
编辑记录。
我把每个函数都放到actionResult中。 ActionResult指数工作正常,但actionResult搜索不起作用,它没有事件转到我设置的断点。
尝试在视图中添加'FormMethod.Post'并在控制器中制作操作'public' – Tushar
控制器的名称是什么? –
@HemantBhagat由于他说'Index'方法正在工作,它应该是'DisplayTableController'。 – InvisiblePanda