2

I have action method

[HttpPost]
        public virtual ActionResult Search(string searchTerm)
...

And Form

@using (Html.BeginForm(MVC.Products.Search(), FormMethod.Post))
        {
            <input id="searchBox" name="searchTerm" type="text" />
            <input type="submit" value="Search" />
        }

But this will not work, Search() require searchTerm parameter and I don't know how to pass it?

1110
  • 7,829
  • 55
  • 176
  • 334

2 Answers2

2

You could pass null:

@using (Html.BeginForm(MVC.Products.Search(null), FormMethod.Post))
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • T4MVC always generates an overload that takes no params, so I would have thought that not passing anything would have worked. – David Ebbo May 01 '12 at 18:42
0

Check your T4MVC ProductsController.generated.cs file for a Search() method that takes zero parameters. It sounds like you won't find it there, but as David Ebbo posted above, it should have been generated under most circumstances. It is especially strange considering that the method you pasted here is decorated as virtual, which probably happened at some point previously when it was tagged by T4MVC.

So, to fix it, you might try deleting your *.generated.cs files and regenerating them, by right-clicking the T4MVC file in the VS IDE and selecting "Run Custom Tool".

If the zero-param method still isn't generated but other are, inspect what might be unusual about your Search method. You might be doing something unsupported by T4MVC. This happened to me today for a method with a String return. I had to either use the null parameter hack or return a ContentResult, as per In MVC, how do I return a string result?, which David kindly referenced at T4MVC and Ajax method with parameter .

Community
  • 1
  • 1
shannon
  • 8,664
  • 5
  • 44
  • 74
  • Which, by the way, set my headers properly and did other nice stuff. I don't have any need for T4MVC to support a string return. – shannon May 31 '12 at 00:31