MVC重定向到一个视图没有控制器 [英] MVC redirect to a view without a controller

查看:248
本文介绍了MVC重定向到一个视图没有控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

希望应该是一个简单的。我创建了我要当一个异常中整个网站的操作方法时,显示一般错误观点。我已经创建,所有的导航生活所以因此我不需要这个观点控制器部分页面,让我怎么重定向到它从一个控制器内部的操作方法?

Hopefully should be a simple one. I have created a generic error view that I want to show when a exception occurs inside action methods across the site. I have created a partial page where all the navigation lives so therefore I do not need a controller on this view, so how do I redirect to it from a action method inside a controller?

这样的事情...

 [HttpPost]
 public ActionResult Test(VM viewModel)
 { 
     try
     {
         // posting info to the server...
     }
     catch (Exception ex)
     {
        //Log exception..

        //show an error view, however no action method so how do I redirect?
        return RedirectTo ??? ("Error");
     }
  }

在此先感谢

推荐答案

您可以使用返回查看()

这告诉MVC生成HTML要显示指定的视图,并将其发送给浏览器。这就像为 Server.Transfer的()在Asp.Net WebForm中

This tells MVC to generate HTML to be displayed for the specified view and sends it to the browser. This acts like as Server.Transfer() in Asp.Net WebForm.

     {
       //Log exception..    
        //show an error view, however no action method so how do I redirect?
        return View("your view path");
     }

这篇关于MVC重定向到一个视图没有控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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