8
Vote

Html.BeginForm<T> does not the same things as Html.BeginForm()

description

Hi!

I'm using the Html.EnableClientValidation() method. When I use Html.BeginForm(...), it works fine. When I use Html.BeginForm<T>(...), it does not work.

The generated javascript have this setting: "FormId":"null"

I think it's because the generic does'nt set the FormContext.FormId property.

comments

maird wrote Jun 1, 2010 at 7:31 PM

I'm running into a related, but different, issue with Html.BeginForm. For some reason, it is picking up on a Route to an Area when it shouldn't. Html.BeginForm correctly renders the form action without the Area prefix.

maird wrote Jun 1, 2010 at 7:31 PM

I'm running into a related, but different, issue with Html.BeginForm. For some reason, it is picking up on a Route to an Area when it shouldn't. Html.BeginForm correctly renders the form action without the Area prefix.

ondrejsv wrote Aug 24, 2010 at 10:18 PM

The generic version does not make use of these lines included in the FormHelper extension method which the non-generic BeginForm uses:
        if (htmlHelper.ViewContext.ClientValidationEnabled) {
            // forms must have an ID for client validation
            tagBuilder.GenerateId(htmlHelper.ViewContext.FormIdGenerator());
        }
The fix is easy, just include those lines. Meantime you can use your own extension method (copy the source from the MvcFutures project\Mvc\FormExtensions.cs) with the afore mentioned lines.

sydneyos wrote Sep 8, 2010 at 11:49 PM

If I try to add these lines, I get "ViewContext does not contain a definition for 'FormIdGenerator'" - seems to be an internal property.

billrob458 wrote Sep 16, 2010 at 4:09 AM

This ticket should be called.

Html.BeginForm does not work with mvc ajax client validation.

mozingod wrote Nov 4, 2010 at 7:43 PM

@maird: In the LinkBuilder class, modify the BuildUrlFromExpression method to check for the key "Area" in the routeValues parameter. If it's there, call GetVirtualPathForArea, otherwise call GetVirtualPath. That'll fix it building the wrong path for the form action.