Типизированная обертка для View

Редактировал(а) Alexandr Fokin 2022/11/23 11:56

Комментарий:

Можно реализовать несколькими способами, задача примера - передать суть способа.


public static class TypedViewRegistry
{
   #region ViewName

   private static string ViewFile { get; set; }
        = @"~/Views/Partial/Calendar/CalendarPartialView.cshtml";

   public static ViewResult GetViewName(
        BaseMvcController controller,
        TypedModel model
        )
    {
       return controller.View(
            ViewFile,
            model
            );
    }

   public static async ValueTask<IHtmlContent> GetPartialViewNameAsync(
        IHtmlHelper html,
        TypedModel model
        )
    {
       return await html.PartialAsync(
            ViewFile,
            model
            );
    }

   #endregion
}
Теги: