2014-10-31 33 views
0

我的要求是,会有一个控制器方法,它会处理所有的请求,可能返回MVCview/model,或者它可能返回.ASPX页面,无论如何URL必须是相同。MVC到web表单重定向而不改变URL

像下面的东西。

public ActionResult HandleRequest() 
    { 
     if(Module is Converted) 
     { 
      return view(ModuleName); 
     } 
     else 
     { 
    //return module.aspx page, Here I can user Redirect method but it will change URL 
    //I don't want browser's Url to be changed. 
     } 
    } 
+1

只是为了澄清事实,你想拥有的多个视图一个通过一个URL字符串加载。加载的视图基于未包含在URL字符串中的逻辑...此后,您要加载页面并仍然保留现有字符串。这是你想要达到的目标吗? – AbdulG 2014-10-31 08:12:54

+0

@AbdulG,是的,你得到了点, 让我们说... www.mysite.com/Controller/Action链接应该能够加载任何视图,或webform.aspx页面,而无需更改其URL。 – 2014-10-31 08:49:17

+0

那么你可以通过部分视图实现这一点。使用模板视图(可能只是将其命名为“HandleRequest”,以便它可以与您现有的操作一起返回)。从那里,你可以渲染你的局部视图,在你的模板中,根据你计划使用的任何逻辑来执行 – AbdulG 2014-10-31 09:08:39

回答

1
Your answer is Routing. 

    http://msdn.microsoft.com/en-us/library/cc668201.aspx 



Look at following code : 

public ActionResult Test() 
     { 
      ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application."; 

      return RedirectToAction("TestAspx"); 
     } 


     public ActionResult TestAspx() 
     { 
      ViewBag.Message = "Your app Test aspx page."; 

      return View(); 
     } 


Here the action TestAspx() returns an TestAspx.aspx view. 

And for the Routing 

public static void RegisterRoutes(RouteCollection routes) 
     { 
      routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 
      routes.MapRoute(
       "TestAspx", 
       "testganesh", 
       new { controller = "Home", action = "TestAspx" } 
      ); 


      routes.MapRoute(
       name: "Default", 
       url: "{controller}/{action}/{id}", 
       defaults: new {controller = "Home", action = "Index", id = UrlParameter.Optional} 
       ); 


     } 

Please make appropriate changes to the routing names that you need. 

Hope this will help. 

Let me know if you still face any issue. 

Mark as right if the issue got fixed. 
:) 
+0

你能否简单介绍一下,因为这个aspx页面是物理文件,所以我认为它不会起作用,并且不能更改URL。 – 2014-10-31 07:08:48

+1

我不认为路由将达到什么@DotNetIsMyPower要求 – AbdulG 2014-10-31 08:10:27

+0

嗨Moksh, 我已经更新了我的答案。 希望这会有所帮助。 – 2014-10-31 15:32:27