0

Edit: I forgot to mention neither the ActionLink<> or BeginForm<> has worked form me, I have latest MVC version (looked at the available updates for project from NUGET , mvc was not in the recommended list). Is there a sample tutorial/example that uses this feature?

In question "What is an alternative to using strings for action and controller names in asp.net MVC?" I received an answer to use this answer What is the syntax for a strongly-typed ActionLink in MVC 4 with MVC 4 Futures?

I have tried to do what they have done with Action link e.g. :

@(Html.ActionLink<CustomersController>(x => x.Index(), "Customers"))

But similar did not even compile :

Html.BeginForm<CustomersController>(x => x.Index())

Is there some namespace I need to add or a different syntax I need to try?

Update 2 : This is what I have :

@using (Html.BeginForm<UnitTestsController>( x => x.Index()) )

UnitTestsController is refereced ok, intellisense wouldn't even allow x => x.Index()) , I had to hammer it in.

Also added System.Linq namespace, but is not being used (grayed out by Reshaper) The error at run time is :

Compiler Error Message: CS0308: The non-generic method 'System.Web.Mvc.Ajax.AjaxExtensions.BeginForm(System.Web.Mvc.AjaxHelper, string, string, System.Web.Routing.RouteValueDictionary, System.Web.Mvc.Ajax.AjaxOptions, System.Collections.Generic.IDictionary)' cannot be used with type arguments

5
  • 1
    Which one are using - T4MVC or MVC4 Futures? Commented Sep 21, 2016 at 3:50
  • @StephenMuecke MVC4 Commented Sep 21, 2016 at 3:54
  • 1
    Did you include the Microsoft.Web.Mvc namespace? And FYI, refer this answer for info on the 'Futures' project Commented Sep 21, 2016 at 3:58
  • 1
    Note you can find the source code for the BeginForm() method here and the ActionLink() here Commented Sep 21, 2016 at 4:05
  • 1
    Similar problem here: stackoverflow.com/questions/2880056/…. The standard BeginForm provided by System.Web.Mvc currently doesn't include type arguments, thus you need to create custom html form helper or use MVC4 Futures. Commented Sep 21, 2016 at 7:57

1 Answer 1

1

I don't know if you miss to complete your post but I notice you forgot to "end" the BeginForm? Technically there are two ways to use Html.BeginForm.

Manually end the form :

@{ Html.BeginForm<CustomersController>(x => x.Index()); }
   <input type="text" id="txtQuery"/>
   <input type="submit" value="submit"/>
@{ Html.EndForm(); }

Or for your convenience you can use using() {} to ensure and proper close the form tag:

@using (Html.BeginForm<CustomersController>(x => x.Index())) 
{
    <input type="text" id="txtQuery"/>
    <input type="submit" value="submit"/>    
}

Can you try this approach if this will compile correct for you.

Sign up to request clarification or add additional context in comments.

4 Comments

What namespaces are you using? still no joy
BTW L I was using @using way of BeginForm, did not seem important to include that.
What is the result after your tried this? Have you encounter exception? Have you reference your controller in you view?
Added more info at the end of my post, yes controller was refrenced, is there a fully qualified name for generic Html.BeginForm ? I am using VS2013

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.