c# - c#“x”不包含“y”的定义
问题描述
由于我对 C# 和 OOP 的初级理解,我遇到了一些问题。但是我一直无法通过寻找答案来理解我做错了什么。
我的模型 - KeyVisualBlock.cs:
[Display(Order = 90,
GroupName = SystemTabNames.Content)]
[AllowedTypes(typeof(FormContainerBlock))]
public virtual ContentReference ContactForm { get; set; }
我的控制器 - KeyVisualBlockController.cs:
using System.Web.Mvc;
using Example.Site.Models.Blocks;
using Example.Site.Models.Pages;
using Example.Site.Models.ViewModels;
using EPiServer;
using EPiServer.ServiceLocation;
using EPiServer.Web;
using EPiServer.Web.Mvc;
namespace Example.Site.Controllers
{
public class KeyVisualBlockController : BlockController<KeyVisualBlock>
{
public override ActionResult Index(KeyVisualBlock currentBlock)
{
var contentLoader = ServiceLocator.Current.GetInstance<IContentLoader>();
var startPage = contentLoader.Get<StartPage>(SiteDefinition.Current.StartPage);
KeyVisualBlockViewModel model = new KeyVisualBlockViewModel
{
SearchLink = startPage.SearchPageLink,
CurrentKeyVisualBlock = currentBlock
};
return PartialView("KeyVisualBlock", model);
}
}
public class KeyContactBlockController : BlockController<ContactBlock>
{
public override ActionResult Index(ContactBlock currentBlock)
{
ContactBlockViewModel model = new ContactBlockViewModel(currentBlock);
return PartialView("~/Views/Shared/Blocks/ContactBlock.cshtml", model);
}
}
}
我的视图模型:
using Example.Site.Models.Blocks;
using EPiServer;
using EPiServer.Core;
using EPiServer.Forms.Implementation.Elements;
using EPiServer.ServiceLocation;
using System;
namespace Example.Site.Models.ViewModels
{
public class KeyVisualBlockViewModel
{
public PageReference SearchLink { get; set; }
public KeyVisualBlock CurrentKeyVisualBlock { get; set; }
}
public class KeyContactBlockViewModel
{
public KeyContactBlockViewModel(ContactBlock KeycurrentBlock)
{
IContentLoader contentLoader = ServiceLocator.Current.GetInstance<IContentLoader>();
this.KeyCurrentBlock = KeycurrentBlock;
if (!ContentReference.IsNullOrEmpty(this.KeyCurrentBlock.ContactForm))
{
this.ContactFormID = contentLoader.Get<FormContainerBlock>(this.KeyCurrentBlock.ContactForm)?.Form?.FormGuid;
}
}
public ContactBlock KeyCurrentBlock { get; set; }
public Guid? ContactFormID { get; set; }
}
}
最后是我的观点:
<header>
<h2 id="@(string.Format("formWrapperHeader_{0}", Model.ContactFormID))"
data-header-success-message="@Model.KeyCurrentBlock.SuccessHeadline">
@Html.PropertyFor(x => x.KeyCurrentBlock.Headline)
</h2>
</header>
我在视图中得到的错误如下:
“KeyVisualBlockViewModel”不包含“KeyCurrentBlock”的定义,并且找不到接受“KeyVisualBlockViewModel”类型的第一个参数的可访问扩展方法“KeyCurrentBlock”(您是否缺少 using 指令或程序集引用?)
我要做的是添加将表单包含到我们的 KeyVisualBlock 中的功能,以便我们的编辑器可以将表单包含到我们的页眉部分中。
解决方案
推荐阅读
- c++ - C++ 语言特性:在类或方法声明中使用方括号 [[ ]]
- android - 当我正确声明时为什么会出现此错误?
- c++ - 通过带有分隔符的 ifstream 读取文件
- java - 如何在gridview android studio的一个视图中制作2个布局
- javascript - 在破坏程序之前,我可以从 Javascript 循环中调用延迟函数多少次?
- r - 根据 R 中的条件对列中的行求和
- asp.net - 重定向后请求中不存在 Set-Cookie 标头
- variables - 将键的值放置在其他变量键值中 - Ansible
- python - Django迁移重新排序列
- flutter - Flutter:列表视图构建器不查看搜索结果