ASP.NET BeginForm() 表达式语法
我想对 ASP.NET MVC 的 Html.BeginForm 使用基于表达式的语法(例如 Html.BeginForm
我不清楚相应操作有参数时要做什么。例如,我有一个仅 HTTP POST 的登录操作,并且有两个参数:用户名和密码,
如果我使用基于表达式的语法,我最终会得到 Html.BeginForm<。 ;MyAccountController>(a => a.Login(null null)); - 对于 BeginForm 表达式,空对(根据操作签名是必需的)似乎是多余的
。获取 FormCollection 实例,这将如何与表达式一起使用?
谢谢, 德里克.
I'd like to use the expression-based syntax for ASP.NET MVC's Html.BeginForm (e.g. Html.BeginForm<HomeController>(a => a.ActionForSubmit();) for the increased testability it gives you.
I'm unclear about what to do where the corresponding action has parameters. For example, I have a login action that is HTTP POST only and has two parameters: username, and password.
If I use the expression-based syntax I end up with Html.BeginForm<MyAccountController>(a => a.Login(null null)); - the null pair (required as per the action signature) seem superflous to me for the BeginForm expression. Am I specifying the expression incorrectly?
If the corresponding action was to take a FormCollection instance how would this work with the expression?
Thanks,
Derek.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您只需传入
string.Empty
,它就会在您发布表单时填写。我不会传递 null 。 会发生什么,它会首先接受您传递到表达式中的内容,然后用发布的表单中的任何内容覆盖它。 我发现使用 string.Empty 而不是 null 是最佳实践。
You can just pass in
string.Empty
and it'll be filled in when you post the form.I wouldn't pass in null. What happens it it'll accept what you passed into the expression first and then overwrite that with anything from the posted form. I find it a best practice to use string.Empty instead of null.