Umbraco 7-if字段

如何解决Umbraco 7-if字段

我对此很陌生,正在使用Umbraco v7中已经存在的网站。

我试图在属性别名freeProgram为true时显示Free一词。

FreeProgram已经在文档类型程序上设置了一个复选框

它被用来创建过滤器,并且在一些地方被引用

此内容是通过部分模板创建的-这是代码(如果freeProgram为true,则包括创建内容的许多尝试中的一部分)

@model PerformanceSpace.Models.VM_Cards

@{ var imgurl = String.Format("{0}?width={1}&height={2}&mode=crop",Model.imgUrl,Model.doubleCrop ? 700 : 400,Model.doubleCrop ? 400 : Model.smallCard ? 400 : 496); }

    <div class="card-image">
        @if (!String.IsNullOrEmpty(Model.imgUrl))
        {
            <img src="@imgurl" alt="@Model.imgAlt">}
    </div>


    @if (Model.smallCard)
    {
        <div class="py16 px16">
            <h3 class="h6 mb0 card--title" style="color:@Model.txtColour !important">
                @Model.title
            </h3>
        </div> }

    else
    {
        <h3 class="h6 mb0 card__heading">
            <span class="text--hl card--title" style="background-color:@Model.colour;">
                @Model.title
            </span>
        </h3>}

    <div class="card__date mt16" style="color:@Model.txtColour !important">
        <small>@Model.subTitle</small>
    </div>
</a>

@{
    if (!Model.Value<bool>("freeProgram"))
    {
        <p>The Checkbox is not checked!</p>
    }
}

当前,这可防止打开物品。追溯过去(记住我对此一无所知)

我尝试了许多不同的语法,并复制了控制器中用于获取相同内容的if语句

@if (model.freeProgram)
{
    <div>free</div>
}

这是包含VMCards类的模型

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Web;
using Umbraco.Web;
using Umbraco.Web.PublishedContentModels;

namespace PerformanceSpace.Models
{
    public class VM_RelatedCards
    {
        public string   areaTitle       { get; set; }
        public bool     pastOnly        { get; set; }
        public string   pastURL         { get; set; }
        public string   currentURL      { get; set; }
        public int      displayLimit    { get; set; }
        public string   card1Colour     { get; set; }
        public string   cardTextColour  { get; set; }
        public string   card2Colour     { get; set; }
        public string   card3Colour     { get; set; }
        public bool     altSizes        { get; set; }
        public bool     doubleSizeFirst { get; set; }
        public bool     noCurrentPast   { get; set; }
        public bool     showline        { get; set; }

        public List<VM_Cards> cards { get; set; }


        public VM_RelatedCards()
        {
            init();
        }

        public VM_RelatedCards(IEnumerable<Artist> inputList)
        {
            init(inputList);
        }

        public VM_RelatedCards(IEnumerable<Program> inputList)
        {
            init(inputList);
        }

        public VM_RelatedCards(IEnumerable<Umbraco.Core.Models.IPublishedContent> inputList)
        {
            init(inputList);
        }

        private void init(IEnumerable<Umbraco.Core.Models.IPublishedContent> input = null,bool sizeAlternation = false)
        {
            pastOnly        = true;
            displayLimit    = 3;
            cards           = new List<VM_Cards>();
            altSizes        = sizeAlternation;
            doubleSizeFirst = false;
            noCurrentPast   = false;
            showline        = true;

            if (input != null && input.Count() > 0) {
                var T = input.First().GetType();

                if (T == typeof(Artist)) {
                    foreach (Artist item in input) {
                        cards.Add(new VM_Cards(item)); } }
                else if(T == typeof(Program)) {
                    foreach (Program item in input) { 
                        cards.Add(new VM_Cards(item)); } }
                else if(T== typeof(BlogPost)) {
                    foreach(BlogPost item in input) {
                        cards.Add(new VM_Cards(item)); } } } 
        }

        private void init(IEnumerable<Artist> inputList)
        {
            init();

            for (int count = 0; count < inputList.Count(); count++) {
                var item = inputList.ElementAt(count);

                cards.Add(new VM_Cards(item)); }
        }

        private void init(IEnumerable<Program> inputList)
        {
            init();

            foreach (var item in inputList) {
                cards.Add(new VM_Cards(item)); }
        }
    }


    public class VM_Cards
    {
        public string colour    { get; set; }
        public string txtColour { get; set; }
        public string title     { get; set; }
        public string subTitle  { get; set; }
        public string imgUrl    { get; set; }
        public string imgAlt    { get; set; }
        public string linkURL   { get; set; }
        public bool   smallCard { get; set; }
        public string cellClass { get; set; }
        public bool doubleCrop  { get; set; }
        public bool freeProgram  { get; set; }
        public bool onlineProgram { get; set; }

        public VM_Cards()
        {
            smallCard   = false;
            doubleCrop  = false;
            freeProgram = false;

        }

        public VM_Cards(Artist input,bool small = false,string textColour = null)
        {
            this.colour = input.HeadingColours.GetPropertyValue<string>("backgroundColour");
            txtColour   = textColour ?? gFuncs.textColourFromBG(colour);
            title       = input.FirstName + " " + input.LastName;
            subTitle    = input.HeadingText;
            imgUrl      = input.BiographyImage != null ? input.BiographyImage.Url : input.HeadingHeroImage.Url;
            imgAlt      = input.BiographyImage == null ? input.HeadingHeroImage.Name : input.BiographyImage.Name;
            smallCard   = small;
            cellClass   = "mb32";
            linkURL     = input.Url;
            doubleCrop  = false;
        }

        public VM_Cards(Program input,string textColour = null)
        {
            string format   = (input.ProgramDates != null) ? ((List<Umbraco.Core.Models.IPublishedContent>)input.ProgramDates).ToMultiDate().MaxDate().Date <= DateTime.Now.AddMonths(-8) ? "MMM d,yyyy" : "MMM d" : null;
            this.colour     = input.HeadingColours.GetPropertyValue<string>("backgroundColour");
            title           = input.Title;
            subTitle        = input.ProgramDates != null ? input.ProgramDates.ToList().ToMultiDate().MinDate().ToString(format) + ((input.ProgramDates.Count() > 1) ? " - " + input.ProgramDates.ToList().ToMultiDate().MaxDate().ToString(format) : "") : "";
            imgUrl          = input.HeadingHeroImage.Url;
            linkURL         = input.Url;
            smallCard       = small;
            txtColour       = textColour ?? gFuncs.textColourFromBG(colour);
            cellClass       = "mb32";
            doubleCrop      = false;
            freeProgram     = "free";
        }

        public VM_Cards(program input,bool small = false) 
        {
            string format   = input.dateFinish.Year < DateTime.Now.Year ? "MMM d,yyyy" : "MMM d";
            colour          = input.bgColour;
            txtColour       = gFuncs.textColourFromBG(input.fgColour);
            title           = input.heading;


            if (input.dateStart == new DateTime())
            {
                subTitle = "TBC";
            }
            else
            {
                subTitle = input.dateStart.ToString(format) + (input.dateStart.Date != input.dateFinish.Date ? " - " + input.dateFinish.ToString(format) : null);
            }
            imgUrl          = input.img;
            linkURL         = input.url;
            smallCard       = small;
            cellClass       = "mb32";
            doubleCrop      = false;
            freeProgram = "free";
        }

        public VM_Cards(BlogPost input,bool dblCrop = false)
        {
            //string format = "dddd MMMM dd yyyy";
            title           = input.Title;
            //subTitle      = input.CreateDate.ToString(format);
            imgUrl          = input.FeatureImage.Url;
            imgAlt          = input.FeatureImage.Name;
            linkURL         = input.Url;
            colour          = input.CardColour as string;
            txtColour       = gFuncs.textColourFromBG(colour);
            doubleCrop      = dblCrop;
        }
    }
}

因此,据我了解,这似乎不是通过创建文档类型创建的模型-没有称为VM的文档类型

freeProgam属性别名最初是在Property模型中设置的。这是属性模型头和相关代码。

            //------------------------------------------------------------------------------
// <auto-generated>
//   This code was generated by a tool.
//
//    Umbraco.ModelsBuilder v3.0.10.102
//
//   Changes to this file will be lost if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Web;
using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Web;
using Umbraco.ModelsBuilder;
using Umbraco.ModelsBuilder.Umbraco;

namespace Umbraco.Web.PublishedContentModels
{
.
.
.


///<summary>
        /// Free Program: Is this a free program?
        ///</summary>
        [ImplementPropertyType("freeProgram")]
        public bool FreeProgram
        {
            get { return this.GetPropertyValue<bool>("freeProgram"); }
        }

我想我不理解用modelsbuilder创建的模型与如何在另一个名称空间中使用它们之间的关系(我什至不确定该名称空间是什么,但我猜想它会以某种方式将它们分开)

所以我想做的是在设置了该属性别名的项目中添加free这个词。我要去哪里错了?非常感谢。有人告诉我这是一个Wordpress网站,我的期限很紧,现在他们找不到其他人可以这样做,而且该网站在两天内上线了……呃……。

解决方法

如果该部分模板实际上已渲染并且正确填充了模型VM_Cards,那么您应该能够做到

@if(Model.freeProgram) {
   <p>Really free</p>
}

尝试显示该属性的值时遇到任何错误吗?

此外,类VM_Cards具有一些不同的构造函数,并且freeProgram并未在所有构造函数中初始化。

您能显示传递给视图的模型是如何构建的吗?在代码中的某个位置可能有一个控制器(.cs文件),该控制器构造了传递给视图的模型?在代码库中搜索部分视图的名称(不带.cshtml),您应该能够找到将VM_Cards传递到视图的代码。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-