MVC - 麻烦链接到另一个控制器/动作 [英] MVC - trouble linking to another Controller/Action

查看:173
本文介绍了MVC - 麻烦链接到另一个控制器/动作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有什么,我会打电话给ControllerA从中我想HREF /链接到一个视图中的另一个控制器(ControllerB),并有一个视图(ViewB)提出了在另一个浏览器选项卡中的视图。我尝试了明显的方法。

i have a view in what i'll call ControllerA from which i want to href/link to a view in another controller (ControllerB) and have that view (ViewB) come up in another browser tab. i tried the obvious method..

从ViewA ..

<a href="/ControllerB/ActionB" target="_blank">SomeText</a> 

ActionB不常用的返回查看();

ActionB does the usual return View();

问题是,当我点击链接上,一个新的选项卡打开,但我得到这个错误。

the problem is when i click on the link, a new tab is opened but i get this error..

资源无法找到。 说明:HTTP 404。您正在寻找(或它的一个依赖项)可能已被移除的资源,有其名称更改,或者暂时不可用。请检查以下URL并确保其拼写正确。

The resource cannot be found. Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

请求的URL:/ ControllerB / ActionB

Requested URL: /ControllerB/ActionB

不明白这一点。我可以100%保证,该控制器存在于项目中的控制器/ ControllerB目录。

don't get it. i can 100% guarantee that that controller exists in the Controllers/ControllerB directory in the project.

和是我没有尝试这个以及..

and yes i did try this as well..

<a href="@Url.Action("ActionB", "ControllerB")" target="_blank">SomeText</a>

但同样的问题。

but same problem.

干了什么(在某种程度上)的工作,虽然是建立在ViewA在hre​​f调用JScript函数(HREF =JavaScript的:函数())。该功能使用jQuery的Ajax调用跳入ControllerB(使用相同的URL如上),这实际工作(它停止在返回视图()在调试器)。问题是,没有什么事情发生。没有新的选项卡被打开和视图不出现的任何地方。

what did (sort of) work though was setting up the href in ViewA to call a jscript function (href="javascript:function()"). that function uses a jquery ajax call to jump into ControllerB (using the same url as above) and this actually works (it stops on the return View() in the debugger). the problem is, nothing else happens. no new tab is opened and the view doesn't appear anywhere.

我怎么能做到这一点/我究竟做错了什么?

how can i do this/what am i doing wrong?

编辑:也试图与相同的结果。

edit: also tried this with the same result..

@Html.ActionLink("SignalR", "SRStart", "SignalR", null, new { target = "_blank" }) 

事做也许路由?

something to do with routing maybe?

编辑#2: 我以前见过这个版本的错误。这取决于我如何设置的网址,我会得到更详细的404错误的详细信息,其中包括这个..

edit #2: i've seen this version of the error before. depending on how i set up the url, i'll get a more detailed 404 error the details of which include this..

请求的URL的http://本地主机:64528 /主页/〜/ SignalR / SRStart

Requested URL http:// localhost:64528 /Home /~ /SignalR /SRStart

请注意,Home控制器(或目录 - 不知道),默认情况下附加到URL我指明这是什么原因造成的错误的前面。不知道为什么发生这种情况不是事实,其他包含链接是关闭主控制器(ControllerA),但它的发生,这是一个痛苦的屁股的看法。 所以我想现在的问题是 - 如何prevent被附加到URL前部的电流控制器(主页)?有些应用程序设置的地方?

notice that the Home controller (or directory - not sure) is appended by default to the front of the url i specify which is what is causing the error. not sure why this is happening other than the fact the view that contains the link is off the Home controller (ControllerA) but it's happening and it's a pain the butt. so i guess the question now is - how do i prevent the current controller (Home) from being appended to the front of the url? some application setting somewhere?

推荐答案

嗯,这很有意思。当我贴我的操作方法,我刚刚从改变[HttpPost]属性为[HTTPGET]不认为这会让任何区别,因为的路径问题,但后来我又跑到它和它的工作。不打算pretend我明白为什么家被追加到URL时,我曾发表的属性,但是想这并不重要。所以这是附着在操作方法的属性。有趣。所有的感谢名单..

well this is interesting. when i posted my action method, i had just changed the attribute from [HttpPost] to [HttpGet] not thinking it would make any difference because of the pathing issue but then i ran it again and it worked. not going to pretend i understand why Home was appended to the url when i had Post as the attribute but guess it doesn't matter. so it was the attribute attached to the action method. interesting. thanx all..

这篇关于MVC - 麻烦链接到另一个控制器/动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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