0
我从另一个开发继承下面的代码我试图去理解它,什么做square brackets []
立场?为什么有的有“HttpPost”和一些“HTTPGET”MVC路由属性方括号
namespace webService.Controllers.Scheduler
{
public class testbedsController : EntityController<testbedsService, testbeds>
{
testbedsService p = new testbedsService();
[Route("api/testbeds/")]
[HttpPost]
public testbeds AddOrUpdate(testbeds testbedsInformation)
{
try
{
return p.AddOrUpdate(testbedsInformation);
}
catch (Exception e)
{
throw new Exception(e.ToString());
}
}
}
它的一个[属性] (http://stackoverflow.com/questions/20346/net-what-are-attributes) –
围绕它的方括号的意义是什么?是否有一个或它的正义语法?为什么有些人有'HttpPost'和一些' HttpGet' – user3508811
这就是编译器知道它的一个属性(应用于该方法的元数据)。和[HttpGet](https://msdn.microsoft.com/en-us/library/system.web.mvc.httpgetattribute(v = vs.118).aspx)和[HttpPost](https://msdn.microsoft .com/en-us/library/system.web.mvc.httppostattribute(v = vs.118).aspx)是确定该方法是否可以作为get或post调用的过滤器属性。 –