我已经创建了一个具有页脚名称的Partial视图,并且我试图在名为Index视图的视图中使用它。
我收到以下错误 无法在renderpartial视图中隐式将类型“ void”隐式转换为“ object”错误 @ Html.RenderPartial(“ Footer”,Model.Footerdata);
有人可以帮我吗,我是MVC的新手
请在下面找到代码:
页脚视图:
@using MVC.ViewModels
@model FooterViewModel
<div style="text-align:center;background-color:gainsboro;color:black;border:1px solid;margin-top:2px;padding:10px;">
@Model.CompanyName founded Year: @Model.Year
</div>
页脚ViewModel:
namespace MVC.ViewModels
{
public class FooterViewModel
{
public string CompanyName { get; set; }
public string Year { get; set; }
}
}
索引视图(我打算在其中使用部分视图的主视图):
@using MVC.ViewModels
@model EmployeeListViewModel
.....
@Html.RenderPartial("Footer", Model.Footerdata);
索引ViewModel:
namespace MVC.ViewModels
{
public class EmployeeListViewModel
{
public List<EmployeeViewModel> employees = new List<EmployeeViewModel>();
public string UserName { get; set; }
public FooterViewModel Footerdata { get; set; }
}
}
Employee Controller将调用索引视图:
EmployeeListViewModel emplist = new EmployeeListViewModel();
//footer
emplist.Footerdata = new FooterViewModel();
emplist.Footerdata.CompanyName = "WeForgot";
emplist.Footerdata.Year = DateTime.Now.Year.ToString();
return View("Index", emplist);