How do I add attributes to HTML.BeginForm with ASP.MVC 4?
asp.net-mvc, asp.net-mvc-3, asp.net-mvc-4
Solution
The `-` (dash) is not a valid C# identifier character. Use `_` (underscore) and it will be transformed into `-` so you will get the correct `data-href` in the generated HTML.
@using (Html.BeginForm(null, null,
new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post,
new { data_href = "/User/Account/Login"}))
Problem
I am using the following code: ``` @using (Html.BeginForm(null, null, new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { data-href = "/User/Account/Login"})) ``` Can someone tell me what's wrong with it. I get an error message pointing to data-href and saying: Invalid anonymous type member declarator. Anonymous type members must be declared with a member assignment, simple name or member access