30 lines
1.1 KiB
C#
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);
|
|
}
|
|
}
|
|
} |