what is the use of RouteValueDictonary routeValues in Html.BeginForm()

前端 未结 2 2020
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-19 11:27
@{
    ViewBag.Title = \"About Us\";
}

@using (Html.BeginForm(new RouteValueDictionary { {\"Action\",\"Index\"}}))
{
         


        
2条回答
  •  一生所求
    2020-12-19 11:58

    This is also useful when implementing the ActionFilterAttribute for Redirection purpose. The basic usage of this class is to define the Action name, Controller Name and Area Name

    public class MyActionFilter : ActionFilterAttribute
    {
        public override void OnResultExecuting(ResultExecutingContext filtercontext)
        {
            filtercontext.Result = new RedirectToRouteResult
                (
                    new RouteValueDictionary
                        (
                            new
                            {
                                controller = "ControllerName",
                                action = "ActionName",
                                area = "AreaName"
                            }
                        )
                );
            base.OnResultExecuting(filtercontext);
        }
    }
    

    You can also send the Parameter list like below..

    filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary
                            {
                                {"action", "ActionName"},
                                {"controller", "ControllerName"},
                                {"area", "Area Name"},
                                {"Parameter Name","Parameter Value"}
                            });
    

提交回复
热议问题