关于ASP.NET MVC中Razor功能的几个问题。
1)请查看以下代码:
@helper WelcomeMessage(string username)
{
<p>Welcome, @username.</p>
}
然后您可以像这样调用它:
@WelcomeMessage("John Smith")
@functions{
public string GetSomeString(){
return string.Empty;
}
}
这里有两个Razor函数。一个使用@helper
声明Razor函数,另一个使用@functions。那么告诉我@helper和@functions
之间的区别是什么?
2)我们能否在.cs代码中声明Razor函数...如果可以,那么我们需要遵循任何惯例吗?
3)我们能从Razor函数返回整数吗?
@helper Calculator(int a, int b)
{
@{
var sum = a + b;
}
<b>@sum</b>
}
@Calculator(1, 2)
我们可以将sum返回给它的调用环境吗?