
MVC Controller 中不能重载吗
1个回答
展开全部
同名的时候不能重载
只能有 GET 和POST
还有两个常用的属性是[HttpPost]和[HttpGet]。例如:
[HttpPost]
public ActionResult Index()
{
return View();
}
表示该方法负责处理Http Post动作。
也可以通过 [AcceptVerbs(HttpVerbs.Post)]来设置,[HttpPost]效果一样,只是方便快速开发。
当对重载的action 方法添加[HttpPost] 属性后,ASP.NET MVC 根据进来的HTTP 动作,自动分发请求
给合适的action 方法。例如:
[HttpPost]
[ActionName("Index")]
public ActionResult IndexPost()
{
return View();
}
public ActionResult Index()
{
return View("Index");
}
URL请求GuestBook/Index时,如果是Http Post请求,则由名称为IndexPost的方法执行;其它的请求,则由名称为Index的方法执行。
只能有 GET 和POST
还有两个常用的属性是[HttpPost]和[HttpGet]。例如:
[HttpPost]
public ActionResult Index()
{
return View();
}
表示该方法负责处理Http Post动作。
也可以通过 [AcceptVerbs(HttpVerbs.Post)]来设置,[HttpPost]效果一样,只是方便快速开发。
当对重载的action 方法添加[HttpPost] 属性后,ASP.NET MVC 根据进来的HTTP 动作,自动分发请求
给合适的action 方法。例如:
[HttpPost]
[ActionName("Index")]
public ActionResult IndexPost()
{
return View();
}
public ActionResult Index()
{
return View("Index");
}
URL请求GuestBook/Index时,如果是Http Post请求,则由名称为IndexPost的方法执行;其它的请求,则由名称为Index的方法执行。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询