3

私は次のコードを使用しています:

@using (Html.BeginForm(null, null, 
    new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, 
    new { data-href = "/User/Account/Login"}))

誰かがそれの何が悪いのか教えてもらえますか?data-hrefを指し、次のようなエラーメッセージが表示されます。

匿名タイプのメンバー宣言子が無効です。匿名型のメンバーは、メンバーの割り当て、単純な名前、またはメンバーアクセスで宣言する必要があります

4

1 に答える 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"}))
于 2013-01-01T08:23:36.417 に答える