I have an ASP.NET webforms application and I have created a MVC View and a Layout Page and I have also created a Partial View but it is giving an error while loading in Layout Page. Please see the following error and my code:
Error on _LayoutPage.cshtml
I have added my code bellow:
_LayoutPage.cshtml
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>@ViewBag.Title</title>
</head>
<body>
<p>Bellow table is in Layout page(Master Page)</p>
<table border="1" cellpadding="5" cellspacing="5">
<tr>
<td>@{Html.RenderAction("_Header", "Layout"); }</td>
<td>@RenderBody()</td>
</tr>
</table>
</body>
</html>
LayoutController.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CBT_WebApplication.Library.CS;
using CBT_WebApplicationProject.Models;
namespace CBT_WebApplicationProject.Controllers
{
public class LayoutController : Controller
{
public ActionResult _Header()
{
HeaderVM hvm = new HeaderVM();
hvm.sAltText = "HFI Logo";
hvm.sHomeURL = "~/Home3.aspx";
hvm.sClass = "logo-header";
hvm.sLogoSrc = "/images/graphics/hf-logo-header-blue.png";
return PartialView("~/Views/Header/_Header.cshtml");
}
}
}
_Header.cshtml (Partial View)
@model CBT_WebApplicationProject.Models.HeaderVM
<div id="divHFI" class='@Model.sClass'>
<a href='@Model.sHomeURL'>
<img src='@Model.sLogoSrc' alt='@Model.sAltText' />
</a>
</div>
HeaderVM.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace CBT_WebApplicationProject.Models
{
public class HeaderVM
{
public string sAltText { get; set; }
public string sHomeURL { get; set; }
public string sLogoSrc { get; set; }
public string sClass { get; set; }
}
}