Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# MVC到web表单重定向而不更改URL_C#_Asp.net Mvc_Asp.net Mvc 4_Asp.net Mvc Routing - Fatal编程技术网

C# MVC到web表单重定向而不更改URL

C# MVC到web表单重定向而不更改URL,c#,asp.net-mvc,asp.net-mvc-4,asp.net-mvc-routing,C#,Asp.net Mvc,Asp.net Mvc 4,Asp.net Mvc Routing,我的要求是,将有一个控制器方法,它将处理所有请求,它可能返回MVCview/model,或者它可能返回.ASPX页面,在任何情况下URL都必须相同 有点像跟踪 public ActionResult HandleRequest() { if(Module is Converted) { return view(ModuleName); } else { //return module.a

我的要求是,将有一个控制器方法,它将处理所有请求,它可能返回MVCview/model,或者它可能返回.ASPX页面,在任何情况下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.
       }
    }

请你再简单介绍一下,因为这个aspx页面将是物理文件,所以我认为它不起作用,URL也不能更改。我认为路由将无法实现@DotNetIsMyPower所要求的。只是为了澄清问题,你希望通过一个URL字符串加载多个视图中的一个。加载的视图基于URL字符串中未包含的逻辑。。。此后,您希望加载页面,并且仍然保留现有字符串。这就是你想要达到的目标吗?@AbdulG,是的,你说得对,比方说。。。www.mysite.com/Controller/Action link应该能够加载任何视图或webform.aspx页面,而无需更改其URL。您可以通过部分视图实现这一点。使用模板视图(可能只是将其命名为
HandleRequest
,以便可以将其与现有操作一起返回)。从那里,您可以在模板中呈现部分视图,基于您计划使用的任何逻辑。返回任何视图不是我的问题,我的问题是在某些情况下,我需要在同一URL上呈现.aspx页面。
    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.
:)