ASP.NET BeginForm()表达式语法 [英] ASP.NET BeginForm() expression syntax
问题描述
我想将基于表达式的语法用于ASP.NET MVC的Html.BeginForm(例如Html.BeginForm< HomeController>(a => a.ActionForSubmit();)),以提高可测试性./p>
我不清楚在相应操作具有参数的情况下该怎么做.例如,我有一个仅HTTP POST的登录操作,并且有两个参数:username和password.
如果我使用基于表达式的语法,则最终会看到Html.BeginForm< MyAccountController>(a => a.Login(null null)); -对于BeginForm表达式,空对(根据动作签名需要)对我来说似乎多余.我是否错误地指定了表达式?
如果相应的操作是采取一个FormCollection实例,那么该表达式将如何工作?
谢谢, 德里克.
您只需传递string.Empty
,它将在您发布表单时填写.
我不会传递null.发生什么情况,它将首先接受您传递到表达式中的内容,然后用发布的表单中的任何内容覆盖它.我发现使用string.Empty而不是null是一种最佳实践.
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.
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.
这篇关于ASP.NET BeginForm()表达式语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!