I'm trying to get a hello world web application running with Nancy. It does not compile on and highlights the Get["/"] = parameters => "Hello World";
and does not recognize this symbol.
I must be missing something simple but can't find anything on the web on this problem.
Steps:
added a new class which has this code:
using Nancy; namespace test2 { public class MainModule : NancyModule { Get["/"] = parameters => "Hello World"; } }
Result: Get["/"] = parameters => "Hello World";
doesn't compile
You need to put your route declaration inside the constructor of the MainModule. Putting the declaration straight into the body, of the class, in not a valid C# syntax.
As TheCodeJunkie mentions, Get["/"] = parameters => "Hello World";
needs to be placed in a constructor for the class.
using Nancy;
namespace test2
{
public class MainModule : NancyModule
{
public MainModule() {
Get["/"] = parameters => "Hello World";
}
}
}
除上述内容外,请注意,最新版本的语法已更改,定义现在看起来像
Get("/", parameters => "Hello World");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.