【发布时间】:2015-10-09 01:55:31
【问题描述】:
在我看来,我有两种形式。一种形式的搜索记录。 Goto page {number of page} 的一种形式,支持分页。正如similar question 中几乎所有人所建议的那样,我必须为每个表单创建两个单独的操作。这将使我的工作变得非常轻松,但是在使用这些方法时我遇到了问题。
假设我有以下模型:
public class MyModel
{
public string Name { get; set; }
public string DateOfEmployment { get; set; }
public int? PageNumber { get; set; }
}
以下观点:
@model WebApplication1.Models.MyModel
@using (Html.BeginForm("Index", "Home", FormMethod.Post, new { }))
{
@Html.LabelFor(m => m.DateOfEmployment)
@Html.EditorFor(m => m.DateOfEmployment)
@Html.LabelFor(m => m.Name)
@Html.TextBoxFor(m => m.Name)
<input type='Submit' value='Search' />
}
<!-- Rows goes here-->
@using (Html.BeginForm("Pagination", "Home", FormMethod.Post, new { }))
{
@Html.LabelFor(m => m.PageNumber)
@Html.TextBoxFor(m => m.PageNumber)
<input type='Submit' value='Go' />
}
问题是当用户单击Go 按钮时,我怎么知道搜索字段值是什么来重新创建模型行?。如果我使用单一表单,我不知道单击了哪个按钮(以一种干净的方式)。那么在这种情况下我该怎么办呢?
【问题讨论】:
-
你可以;将搜索字段保存在 Session 中或作为隐藏字段传递。
-
@ErikPhilips 你也同意有两个表格来解决这些问题?
-
为什么需要两个表格?为什么不使用 1 项操作将整个模型与该表单中的所有字段一起使用?
-
@Jakotheshadows 我怎样才能找到点击了哪个按钮?
Go或Search? -
为什么需要两个不同的按钮?有什么区别?
标签: c# asp.net asp.net-mvc asp.net-mvc-4