我的问题是有点类似 How to get a response "stream" from an action in MVC3/Razor?重定向到URL - asp.net VS MVC
,但我已经试过了,没有成功的方法。使用MVC3,.NET4,C#,
详情
林
JavaScript和第三方组件打开文件。
我有一个viewStuff.js
连接到ViewFile.aspx
。
在我viewStuff.js
我有
var component = 'code to initialize'
PREVIOUSLY
我曾经有aspx
页面连接到这个JavaScript和他们工作完全
在我viewStuff.js
我有
component.openFile("http://localhost:8080/ViewFile.aspx");
其重定向到aspx页面
ViewFile.aspx.cs
文件中返回的HTTPResponse
protected void Page_Load(object sender, EventArgs e)
{
this.Response.Clear();
string stuff = "abcd";
this.Response.Write(stuff);
this.Response.End();
}
窗体现在
相关的所有文件数据我想要做的是替换这aspx
与Controller
将返回相同的东西。
在我viewStuff.js
我有
component.openFile("http://localhost:8080/ViewFile/Index");
的Controller
看起来像
public class ViewFileController: Controller{
public ActionResult Index()
{
string stuff = "abcd";
return stuff;
}
}
我唯一的问题是,我的component.openFile()方法是无法使用才能到Controller
MVC网址。 一旦Index()
开始,我就得到了积极的断点,但他们从来没有 受到打击。
我不知道它
- 网址
- MVC - 事实上,网址是方法,而不是物理文件
而且,我不确定如何各地的RouteConfig一团糟()如果这可能有帮助。
编辑:路由配置: -
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
(如果需要的话,我可以得到更多的细节让我downvoting之前知道。)
是否希望viewstuff.js将数据返回到页面或者您是否尝试重定向到另一个页面。不确定我是否在意你的问题,但你可能需要使用JSONResult方法而不是ActionResult – Brian
你可以告诉你路由配置吗? – alexmac
如果您运行应用程序,然后通过'http:// localhost:8080/ViewFile/Index'进入浏览器地址栏,会发生什么?那么断点是否会被击中?另外,你可能想在你的控制器方法中尝试'返回Content(stuff);'。 –