Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is usage of HTML-5 data-* attributes broken in ASP.NET MVC 4 (beta)?

According to this question, I am supposed to be able to write something like this:

@Html.ActionLink( "Delete", "Delete", "Message", new { data_id=id, @class="delete" } )

or as a happy T4MVC user can do:

@Html.ActionLink( "Delete", MVC.Message.Actions.Delete(), new { data_id=id, @class="delete" } )

And get the underscore in "data_id" replaced during rendering:

<a href="/message/delete" class="delete" data-id="42">Delete</a>

However, this seems not to work in the MVC 4 beta. Anyone else seeing this problem?

Is it an intentional change, and if so, what should I do instead?

UPDATE - HOW TO FIX (MANUALLY)

I've applied the following changes to the T4MVC.tt file, which fixes the problem in the generated code:

public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, ActionResult result, object htmlAttributes, string protocol = null, string hostName = null, string fragment = null) {
    //was: return ActionLink(htmlHelper, linkText, result, new RouteValueDictionary(htmlAttributes), protocol, hostName, fragment);
    return htmlHelper.RouteLink(linkText, null, protocol, hostName, fragment, result.GetRouteValueDictionary(), HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes));
}

UPDATE 2 - FIX AVAILABLE

David Ebbo was lightning fast at responding to the reported issue and has already merged the above fix into T4MVC.

UPDATE 3 - FIX THE FIX

Quite embarassingly, the original fix submitted did in fact not work, as it still called an invalid overload. I've now modified the code to do the same as MVC does internally (using their helper method), and notified David to have it included in T4MVC. Grab 2.6.70 from codeplex or update using NuGet when its released, probably shortly.

like image 322
Morten Mertner Avatar asked Mar 06 '12 23:03

Morten Mertner


People also ask

What are HTML methods in MVC?

In MVC, HTML Helper can be considered as a method that returns you a string. This string can describe the specific type of detail of your requirement. Example: We can utilize the HTML Helpers to perform standard HTML tags, for example HTML<input>, and any <img> tags.

What is ASP NET MVC used for?

The ASP.NET MVC framework is a lightweight, highly testable presentation framework that (as with Web Forms-based applications) is integrated with existing ASP.NET features, such as master pages and membership-based authentication. The MVC framework is defined in the System. Web.


1 Answers

Try

@Html.ActionLink( "Delete", "Delete", "Message", null, new { data_id=id, @class="delete" } )

I think that becuase of all the overloads it is assuming your 4th parameter is the routeValues parameter.

like image 81
StanK Avatar answered Oct 19 '22 23:10

StanK