Files
laatzen/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/NestedController.cs
T
2023-04-20 16:01:22 +02:00

30 lines
1.1 KiB
C#

namespace LaaProductionWeb.App_Infrastructure
{
using System;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Web.Mvc;
public abstract class NestedController : Controller
{
protected ViewResult NestedView([CallerMemberName] string viewName = "", [CallerFilePath] string fileName = "")
{
var viewPath = fileName
?.Split(new[] { "Controllers" }, StringSplitOptions.RemoveEmptyEntries)
?.LastOrDefault()
?.Replace("Controller.cs", $"\\{viewName}");
return this.View($"~\\Views{viewPath}.cshtml");
}
protected ViewResult NestedView(object model, [CallerMemberName] string viewName = "", [CallerFilePath] string fileName = "")
{
var viewPath = fileName
?.Split(new[] { "Controllers" }, StringSplitOptions.RemoveEmptyEntries)
?.LastOrDefault()
?.Replace("Controller.cs", $"\\{viewName}");
return this.View($"~\\Views{viewPath}.cshtml", model);
}
}
}