How to make the controller's name hyphen “-” separated?

后端 未结 4 1231
小蘑菇
小蘑菇 2021-01-05 01:08

I am able to use the

[ActionName(\"My-Action-Name\")]
public ActionResult MyActionName()
{
    return View();
}

But I am facing a problem

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-05 01:47

    You can use Attribute Routing.

    It comes in MVC 5 as well.

    You can find some examples below.

    http://blogs.msdn.com/b/webdev/archive/2013/10/17/attribute-routing-in-asp-net-mvc-5.aspx

    [RoutePrefix("Book-Reviews")]
    public class ReviewsController : Controller
    {
        // eg.: /reviews
        [Route]
        public ActionResult Index() { ... }
        // eg.: /reviews/5
        [Route("{reviewId}")]
        public ActionResult Show(int reviewId) { ... }
        // eg.: /reviews/5/edit
        [Route("{reviewId}/edit")]
        public ActionResult Edit(int reviewId) { ... }
    }
    

提交回复
热议问题