将数组从c#函数返回到js var

时间:2015-05-18 02:40:10

标签: javascript c# jquery asp.net

您好我正在尝试将数组从c#传递给js,但它一直告诉我编译错误。这是我的代码:

C#的.NET

public string calls()
{
    string[] listing = new string[5];
    listing[0] = "20-05-2015";
    listing[1] = "22-05-2015";
    listing[2] = "24-05-2015";
    listing[3] = "26-05-2015";
    listing[4] = "28-05-2015";
    string jsonlisting = JsonConvert.SerializeObject(listing);
    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('" + jsonlisting + "')", true);
    return jsonlisting;
}

的jquery / JavaScript的

<script>
    function pageLoad() {
        var unavailableDates = <%=this.calls();%>        
    );
</script>

1 个答案:

答案 0 :(得分:2)

在调用()后直接删除分号。在我创建的示例中,以下简化版本对我有用:

ProfileCake