3

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

1 Answer 1

5

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"}))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.