我在表单中有几个过滤器选项。我已经将动作方法作为动作。代码如下所示。
<% using (Ajax.BeginForm
(new AjaxOptions { UpdateTargetId = "accountsGrid" }))
{ %>
<body style="overflow: scroll">
<%= Html.TextBox("subAccNumber",accId) %>
<%= Html.TextBox("accountName", Name)%>
<%= Html.TextBox("address", address)%>
<%} %>
<%Html.RenderAction("SelectAccounts"); %>
</body>
public PartialViewResult SelectAccounts(string accId,string accountName,string address)
{
// Do some stuff
return PartialView();
}
我可以创建一个字典或所有输入参数(表单控件)并直接传递给action方法吗?或者我必须为每个控件添加单独的参数?
答案 0 :(得分:0)
您有几个选择:
创建视图模型(推荐方法):
public class AccountViewModel
{
public string SubAccNumber { get; set; }
public string AccountName { get; set; }
public string Address { get; set; }
}
并让您的控制器操作接受此视图模型作为参数:
public PartialViewResult SelectAccounts(AccountViewModel account) { ... }
您当前的实现,其中参数作为操作参数传递
从请求中获取参数:
public ActionResult SelectAccounts()
{
var subAccNumber = Request["subAccNumber"];
var accountName = Request["accountName"];
var address = Request["address"];
...
}