Исходный код вики Типизированная обертка для View
Редактировал(а) Alexandr Fokin 2022/11/23 11:56
Последние авторы
| author | version | line-number | content |
|---|---|---|---|
| 1 | ==== Комментарий: ==== | ||
| 2 | |||
| 3 | Можно реализовать несколькими способами, задача примера - передать суть способа. | ||
| 4 | |||
| 5 | ---- | ||
| 6 | |||
| 7 | {{code language="c#"}} | ||
| 8 | public static class TypedViewRegistry | ||
| 9 | { | ||
| 10 | #region ViewName | ||
| 11 | |||
| 12 | private static string ViewFile { get; set; } | ||
| 13 | = @"~/Views/Partial/Calendar/CalendarPartialView.cshtml"; | ||
| 14 | |||
| 15 | public static ViewResult GetViewName( | ||
| 16 | BaseMvcController controller, | ||
| 17 | TypedModel model | ||
| 18 | ) | ||
| 19 | { | ||
| 20 | return controller.View( | ||
| 21 | ViewFile, | ||
| 22 | model | ||
| 23 | ); | ||
| 24 | } | ||
| 25 | |||
| 26 | public static async ValueTask<IHtmlContent> GetPartialViewNameAsync( | ||
| 27 | IHtmlHelper html, | ||
| 28 | TypedModel model | ||
| 29 | ) | ||
| 30 | { | ||
| 31 | return await html.PartialAsync( | ||
| 32 | ViewFile, | ||
| 33 | model | ||
| 34 | ); | ||
| 35 | } | ||
| 36 | |||
| 37 | #endregion | ||
| 38 | } | ||
| 39 | {{/code}} |