如何仅输出选择文本而不是2sxc剃刀模板中的值? [英] How can I output just the text of a select instead of the value in 2sxc razor templates?

查看:44
本文介绍了如何仅输出选择文本而不是2sxc剃刀模板中的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在2sxc App中,在我的内容类型中,我有一个加拿大省的下拉列表,其中有缩写的名称和值.看起来像这样:

In 2sxc App, in my content type, I have a dropdown list of Canadian provinces that have a name and a value for the abbreviation. It looks like this:

不列颠哥伦比亚省:bc艾伯塔省:ab爱德华王子岛:裴

British Columbia:bc Alberta:ab Prince Edward Island:pei

等等.

我希望能够在我的C#剃刀模板中同时使用文本标签和选择值.当我使用@ Content.Province时,它仅输出值,因此,如果我选择不列颠哥伦比亚省,它将输出为"bc".如何输出所选内容的标签,以使其输出不列颠哥伦比亚省"?

I want to be able to use both the text labels and the select value in my c# razor template. When I use @Content.Province, it only outputs the value so if I select British Columbia it outputs it as "bc". How can I output the label of the selection so that it outputs "British Columbia"?

推荐答案

我最终使用了这种方法:

I ended up using this approach:

 @{
    var provinceMappings = new Dictionary<string, string>();
                provinceMappings.Add("ab", "Alberta");
                provinceMappings.Add("bc", "British Columbia");
                provinceMappings.Add("mb", "Manitoba");
                provinceMappings.Add("nb", "New Brunswick");
                provinceMappings.Add("nl", "Newfoundland &amp; Labrador");
                provinceMappings.Add("nwt", "Northwest Territories");
                provinceMappings.Add("ns", "Nova Scotia");
                provinceMappings.Add("nu", "Nunavut");
                provinceMappings.Add("on", "Ontario");
                provinceMappings.Add("pei", "Prince Edward Island");
                provinceMappings.Add("qc", "Quebec");
                provinceMappings.Add("sk", "Saskwatchewan");
                provinceMappings.Add("yt", "Yukon Territories");
    }

@provinceMappings[p]

这篇关于如何仅输出选择文本而不是2sxc剃刀模板中的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆