@using( Html.BeginForm() )
很好用。它产生了这样的结果:<form action="/Account/Profile?setup=true&cats=dogs" method="post">
也就是说,它将原始查询字符串参数传递到POST操作中,然后在Controller操作中,我可以选择哪些参数是相关的,通过添加到RouteValues和RedirectToResult来传递下一步,或者必要地添加。但是,出于样式目的,我需要为我的表单分配一个类。
我尝试了:
@using( Html.BeginForm( "Profile", "Account", args, FormMethod.Post, new { @class = "mainForm" } ) )
它产生了以下结果:
<form action="/Account/Profile?Count=1&Keys=System.Collections.Generic.Dictionary%602%2BKeyCollection%5BSystem.String%2CSystem.Object%5D&Values=System.Collections.Generic.Dictionary%602%2BValueCollection%5BSystem.String%2CSystem.Object%5D" class="mainForm" method="post">
(args
由过滤器生成,是一个RouteValueDictionary)。规范http://msdn.microsoft.com/en-us/library/dd505151.aspx指出,您可以使用System.Web.Routing.RouteValueDictionary传递参数。
我想要的是:<form action="/Account/Profile?setup=true&cats=dogs" class="mainForm" method="post">
我应该提到,我不希望像传递new {key = value}
那样做,因为有相当多的逻辑来确定我将传递给下一步的内容。
这里有什么建议吗?
我被这个看似简单的任务难住了,肯定错过了什么非常明显的东西。