Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 属性参数必须是常量表达式、typeof表达式或属性参数类型的数组创建表达式_C#_String_Asp.net Mvc 3 - Fatal编程技术网

C# 属性参数必须是常量表达式、typeof表达式或属性参数类型的数组创建表达式

C# 属性参数必须是常量表达式、typeof表达式或属性参数类型的数组创建表达式,c#,string,asp.net-mvc-3,C#,String,Asp.net Mvc 3,下面是一个常量类,我用来调用一些帮助程序: public static class SecurityHelpers { public static string AntiforgeryTokenSalt = "tokenFooYouTolkienBladeRunner"; } 下面是我如何在MVC3 web应用程序的一个窗体中调用它: @using (Html.BeginForm("Index", "Checkout", FormMethod.Post)) {

下面是一个常量类,我用来调用一些帮助程序:

public static class SecurityHelpers
{
    public static string AntiforgeryTokenSalt = "tokenFooYouTolkienBladeRunner";         
}
下面是我如何在MVC3 web应用程序的一个窗体中调用它:

@using (Html.BeginForm("Index", "Checkout", FormMethod.Post))
{   
    <input type="hidden" name="amount" value="@Model.PackageCost"/>
    <input type="hidden" name="currency" value="$"/>
    <input type="hidden" name="itemdescription" value="@Model.PackageDescriptor"/>
    <input type="hidden" name="type" value="digital"/>
    @Html.AntiForgeryToken(App.WebUI.Helpers.SecurityHelpers.AntiforgeryTokenSalt)

    <input type="submit" value="Confirmar" class="btn primary frmsubmit" />
}
错误在我的控制器中触发,它表示:

属性参数必须是常量表达式,typeof表达式 或属性参数类型的数组创建表达式


你知道为什么这样不行吗?ValidateAntiForgeryToken decorator的
Salt
属性是一个字符串,而我的常量也是一个字符串,所以我很困惑。

静态字符串不是常量

试着改变

public static string AntiforgeryTokenSalt = "tokenFooYouTolkienBladeRunner"; 

public static string AntiforgeryTokenSalt = "tokenFooYouTolkienBladeRunner"; 
public const string AntiforgeryTokenSalt = "tokenFooYouTolkienBladeRunner";