I want to pass aditional data from my error handler attribute to error view.

This is how I use my attribute:

[ErrorHandler (View = "Error", Title = "Some title", Text = "Some text")]
public ActionResult Delete(int id, string type, DBRepository repository){...}

This is how I pass data:

public class ErrorHandler : HandleErrorAttribute
{
    public string Title { get; set; }
    public string Text { get; set; }
    /*Some other stuff*/

    filterContext.Controller.TempData["CustomErrorTitle"] = Title;
    filterContext.Controller.TempData["CustomErrorText"] = Text;
}

And this is my error view:

@model HandleErrorInfo
@{
    ViewBag.Title = TempData["CustomErrorTitle"];
}
<h1 class="text-danger">@TempData["CustomErrorTitle"]</h1>
<h1 class="text-danger">@TempData["CustomErrorText"]</h1>
@if (Request.IsAuthenticated && User.IsInRole("Admin"))
{
    <div>
        Exception details: @Model.Exception
    </div>
}

My code works, but i don't want to use TempData. Is there other way to pass data without using TempData? Thank you

Related posts

Recent Viewed