在剃刀中获取空异常作为模型 [英] Getting a null exception as model in razor

查看:53
本文介绍了在剃刀中获取空异常作为模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 asp.net mvc4应用程序中有这样的错误视图:

I have an error's view in my asp.net mvc4 application like this:

@model System.Web.Mvc.HandleErrorInfo

@{
    ViewBag.Title = "Erreur";
}
<p>Take it easy</p>
<hgroup class="title">
    <h1 class="error">Erreur = @Model.Exception</h1>
    <h1 class="error">Controller = @Model.ControllerName</h1>
    <h1 class="error">Name = @Model.ActionName</h1>
    <h2 class="error">Une erreur s'est produite lors du traitement de la requête.</h2>    
</hgroup>

控制器代码:

 public class HomeController : Controller
 {
     [HttpGet]
     public ActionResult Index()
     {
         return RedirectToAction("Search");
     }

     public ActionResult Error()
     {
         return View();
     }

     public ActionResult About()
     {
         ViewBag.Message = "Votre page de description d’application.";

         return View();
     }

     public ActionResult Contact()
     {
         ViewBag.Message = "Votre page de contact.";

         return View();
     }

问题是 Model 始终为null.是什么原因呢?

The problem is that the Model is always null. What is the reason for this?

推荐答案

您甚至没有向视图提供错误对象.

You're not even providing the error object to the view.

    public ActionResult Error()
    {



        return View();
    }

这篇关于在剃刀中获取空异常作为模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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