什么是利用Html.BeginForm RouteValueDictonary routeValues​​的() [英] what is the use of RouteValueDictonary routeValues in Html.BeginForm()

查看:337
本文介绍了什么是利用Html.BeginForm RouteValueDictonary routeValues​​的()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

@{
    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做(关于,家)

Is this the actual use of RouteValueDictonary. If so I can do this do by HTML.BeginForm("About","Home")

有人能解释一下实际使用RouteValueDictonary的。
任何帮助将AP preciated。

Can some one explain the actual use of RouteValueDictonary. Any help will be appreciated.

推荐答案

实施 ActionFilterAttribute 重定向目的时,这也很有用。这个类的基本用法是定义动作名字,控制器名称和名称

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"}
                        });

这篇关于什么是利用Html.BeginForm RouteValueDictonary routeValues​​的()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆