views:

382

answers:

1

Hi,

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.

+3  A: 

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.

Chad Moran
Thanks Chad. I guessed this was the answer, it's a shame it makes things a little ugly.
Derek Lawless