Purpose of ActionName

后端 未结 6 1618
渐次进展
渐次进展 2020-11-27 03:37

What\'s the benefit of setting an alias for an action method using the \"ActionName\" attribute? I really don\'t see much benefit of it, in providing the user the option to

6条回答
  •  盖世英雄少女心
    2020-11-27 03:55

    It allows you to start your action with a number or include any character that .net does not allow in an identifier. - The most common reason is it allows you have two Actions with the same signature (see the GET/POST Delete actions of any scaffolded controller)

    For example: you could allow dashes within your url action name http://example.com/products/create-product vs http://example.com/products/createproduct or http://example.com/products/create_product.

    public class ProductsController {
    
        [ActionName("create-product")]
        public ActionResult CreateProduct() {
            return View();
        }
    
    }
    

提交回复
热议问题