AlertResult

If you want to give feedback of an action to user (like the way validationsummary does), you should use AlertResult.

parameters:
  • AlertType : Type of alert (Info, Success, Warning, Error)
  • title: title
  • description: message to display

In your controller you could write:
        [HttpGet]
        public ActionResult About()
        {
            ViewResult view = View();
            return new AlertResult<ViewResult>(view, AlertType.Info, "Some title", "Some description");
        }

Or
        [HttpGet]
        public ActionResult About()
        {
            return View().AndAlert(AlertType.Info, "Some title", "Some description");
        }

Second example is the better

Now in your view, you can use:
<html>
    <body>
        <div class="page">
            @Html.Alert()
            @RenderBody()
        </div>
    </body>
</html>


In order to work properly, you will have to create a view named _Alert.cshtml in your views/shared folder.
@model Alert
<div id="flash" class="alert alert-@Model.AlertType.ToString().ToLower()">
    <strong class="alert-heading">@Model.Title</strong>
    @Html.Raw(Model.Description)
</div>

Last edited Jun 12, 2013 at 12:15 PM by jefflequeux, version 3

Comments

No comments yet.