MVC路由-ActionLink [英] MVC routing - actionlink

查看:53
本文介绍了MVC路由-ActionLink的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设您在.NET MVC中具有给定的控制器,在/VIEW/中具有给定的文件夹.
如果我们有数据并想执行POST,更改视图的最佳方法是什么?这两种情况是:将视图更改为同一视图文件夹中的另一个视图.将视图更改为视图文件夹之外的另一个视图.

Say you have a given controller in .NET MVC, and a given folder in /VIEW/.
What is the best way to change views, if we have data and want to do i.e. a POST? The two cases are: Change the view to another view within the same view-folder. Change the view to another view outside the view-folder.

您首选的方法是什么?我更喜欢@ Html.ActionLink(返回列表",索引")之类的东西,但是,这似乎只能在同一视图文件夹中使用.

What are your preferred methods? I prefer something like @Html.ActionLink("Back to List", "Index"), however this seems to only work within the same view-folder.

所以我有一个离散的问题,是否可以使用@ html.actionlink链接到另一个控制器?还是仅适用于原始控制器内的链接?

So one discrete question I have is, is it possible to use @html.actionlink to link to another controller? Or is it only for links within the original controller?

推荐答案

所以我有一个离散的问题是,是否可以使用@ html.actionlink链接到另一个控制器?还是只为原始控制器内的链接?

So one discrete question I have is, is it possible to use @html.actionlink to link to another controller? Or is it only for links within the original controller?

,可以使用@ html.actionlink链接到另一个控制器.请看下面的语法.

yes, it is possible to use @html.actionlink to link to another controller. Kindly look at the below syntax.

public static MvcHtmlString ActionLink(
    this HtmlHelper htmlHelper,
    string linkText,
    string actionName,
    string controllerName,
    string protocol,
    string hostName,
    string fragment,
    RouteValueDictionary routeValues,
    IDictionary<string, Object> htmlAttributes
)

因此,当您要调用其他控制器时,请在操作名称旁边指定控制器名称.

So when you want to call an different controller, specify the controller name next to action name.

例如:

@ Html.ActionLink(返回列表",索引",主页")

@Html.ActionLink("Back to List", "Index","Home")

@ Html.ActionLink(返回列表",索引",管理")

@Html.ActionLink("Back to List", "Index","Manage")

注意:您可以指定所需的任何控制器名称,如果不指定控制器名称和动作名称,则它将转到当前的控制器和动作.

Note: you can specify any controller name you want, and if dont specify the controller name and action name , then it will go to the current controller and action.

希望这些信息对您有帮助

Hope the information was helpful

谢谢

Karthik

这篇关于MVC路由-ActionLink的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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