下面是使用ASP.NET反应减少模板和_Layout.cshtml的解决方法的代码示例:
My Website
My Website
@RenderBody()
@{
Layout = "_Layout.cshtml";
}
Welcome to My Website
This is the homepage of my website.
@{
Layout = "_Layout.cshtml";
}
About Us
We are a team of developers.
public class HomeController : Controller
{
public IActionResult Index()
{
return View();
}
public IActionResult About()
{
return View();
}
}
这样,当用户访问网站的首页时,将呈现Index.cshtml视图,并使用_Layout.cshtml作为主布局。当用户访问关于页面时,将呈现About.cshtml视图,并使用相同的主布局。