@{ ViewBag.Title = "About Us"; } @using (Html.BeginForm(new RouteValueDictionary { {"Action","Index"}})) { <input type="submit" value="submit"/> }
当我渲染
<form action="/Home/Index" method="post"><input type="submit" value="submit"/>
这是RouteValueDictonary的实际用途吗?如果是这样,我可以通过HTML.BeginForm(“关于”,“主页”)来做到这一点
有人可以解释RouteValueDictonary的实际用途.
任何帮助将不胜感激.
解决方法
在为重定向实现ActionFilterAttribute时,这也很有用.此类的基本用法是定义操作名称,控制器名称和区域名称
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); } }
您也可以发送如下参数列表..
filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary { {"action","ActionName"},{"controller","ControllerName"},{"area","Area Name"},{"Parameter Name","Parameter Value"} });