Attribute Routing not working in areas

前端 未结 2 1124
栀梦
栀梦 2020-12-02 12:57

Scenario: I have a Forms area in my ASP.NET MVC 5 site.

I\'m trying to redirect to the Details Action which uses a custom route defined using the new Attribute Rout

2条回答
  •  一个人的身影
    2020-12-02 13:36

    Moving the AreaRegistration.RegisterAllAreas() to RouteConfig.cs wasn't enough for me. I also needed to use the AreaPrefix parameter for the RouteArea attibute:

    //Use the named parameter "AreaPrefix"
    [RouteArea("AreaName", AreaPrefix = "area-name-in-url")]
    [RoutePrefix("controller-name-in-url")]
    public class SampleController : Controller
    {
        [Route("{actionParameter}")]
        public ActionResult Index(string actionParameter)
        {
            return View();
        }
    }
    

    Edit: At some point, I came across a sample solution from Microsoft that nicely showed how to handle attribute routing. It also showed some nice examples of how to translate a SelectList into an array of input[type="radio"] items as well as doing the same with an array of input[type="checkbox"] items (if I recall). This sample solution is probably a better answer to this question--as well as giving some good examples on displaying radio buttons and checkbox items. If anyone knows of this sample solution, please add a comment with a link to it.

提交回复
热议问题