Skip to content

Extensions

Orbis Alonzo Gutierrez edited this page Aug 23, 2023 · 2 revisions

Extensions

Extensions from library

EnumExtension

Contains the extensions enums;

methods

  • GetAttribute: Read a display attribute and take the name if is null or don't have the attribute take the name of property

Usage example:

public enum Status{
    [Display(Name ="open")]
    Open,
    [Display(Name ="cancelled")]
    Cancelled
}


var status = Status.Open.GetAttribute();

Console.WriteLine(status) //output: open

ControllerExtensions

Extensions for controllers

methods

  • SendNotification: Read a sweetAlert2 alert Incoming in a TempData['Notification'] , is required install SweetAlert2 library or add with cdn to html.

Usage example:

@{
    ViewData["Title"] = "Home Page";
}

<link href="~/lib/sweetalert2/sweetalert2.min.css" rel="stylesheet" />
<script src="~/lib/sweetalert2/sweetalert2.min.js"></script>

<div class="text-center">
    <h1 class="display-4">Welcome</h1>
    <p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
</div>


@Html.RenderAlerts(TempData); // is necessary
public class HomeController : Controller
{
    public IActionResult Index()
    {
        this.SendNotification("Hello World", NotificationType.success);
        return View();
    }
}

Clone this wiki locally