无法将带有[]的索引应用于"方法组"SinglePageApp1类型的表达式.得到["/"]南希

Bar*_*zyk 10 c# linq get nancy

我尝试在URL上创建一个带NancyModules和GET字符串的类,但方法'Get'告诉我:

"错误CS0021无法将[]索引应用于"方法组"类型的表达式...."

我的代码:

using System; using System.Collections.Generic; using System.Linq;
using System.Web; using Nancy; using System.Text;

namespace SinglePageApp1 {
    public class BloodPresureNancy : NancyModule
    {
        public BloodPresureNancy()
        {

            // Get dasn't work
            Get["/"] = _ => "Heloooo";
        }
    } 
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

我添加了引用:Nancy,Nancy.Hosting.asp,它无法正常工作.

小智 19

您目前使用的是什么版本的Nancy?该语法应该适用于版本1.x. 但是,我认为Nancy最近改变了为即将发布的2.0版本注册路由的方式.如果你看看他们在github https://github.com/NancyFx/Nancy/blob/master/samples/Nancy.Demo.Hosting.Self/TestModule.cs上的样本.您将看到不再像上面那样索引不同的动词,实际上就像方法一样引用它们.尝试更改您的代码

    Get("/", _ => {
        //do work here
     });
相反,看看它是否适合你.