一把umbraco:创建与MVC模式prevalues的CheckBoxList财产 [英] Umbraco: Create CheckBoxList property with prevalues from mvc model
问题描述
我想要做的就是创建一个的CheckBoxList属性,因此编辑器可以选择特定于当前页面(酒店名)在BO设施,以及基于什么被选中呈现内容。
What I want to do is create a CheckBoxList property so the editor could choose facilities specific for current page (hotel name) in BO, and render content based on what is checked.
我已经创建了一个模型:
I've created a model:
public class Facility
{
public int Id { get; set; }
public string Description { get; set; }
public string IconUrl { get; set; }
public List<Facility> GetFacilities()
{
return new List<Facility>()
{
new Facility() { Id = 4, Description = "Free parking", IconUrl = "" },
new Facility() { Id = 6, Description = "Spa", IconUrl = "" },
new Facility() { Id = 7, Description = "Free Wifi", IconUrl = "" },
new Facility() { Id = 2, Description = "Tennis", IconUrl = "" },
new Facility() { Id = 9, Description = "Room service", IconUrl = "" },
new Facility() { Id = 10, Description = "Fitness", IconUrl = "" }
};
}
}
如何创建与GetFacilities()方法来设置值的CheckBoxList?或者我应该创建应用程序code文件夹中的新类用这种方法?哪里是把这种功能最好的地方,我怎么能做到这一点?
How can I create a CheckBoxList with the values set in GetFacilities() method? Or should I create a new class in AppCode folder with this method? Where is the best place to put this kind of functionality, and how can I achieve this?
推荐答案
我想你想这个错误的方式由斯蒂芬的建议(除非我误解你的问题)。所创建的键/值对的列表并且只有一个会在薄来选择,因此只有一个会发布到前端(无论它的使用的)。
I think you're thinking about this the wrong way as suggested by Stephen (unless I am misunderstanding your question). You are creating a list of key/value pairs and only one will be selected in the BO and so only one will published to the front-end (regardless of the use of it).
因此,在BO你只需要一个下拉列表中的键/值对。您可以使用下拉列表(发布密钥)数据类型创建此。也可以考虑使用SQL下拉名单数据类型,因为这会给你更大的灵活性。
So, in the BO you only need a dropdown list with the key/values pairs. You can create this with the "Dropdown list (publishing keys)" datatype. Also consider using the "SQL dropdown" list datatype as this would give you far more flexibility.
如果你这时就需要选定的ID转换成基金
对象,这样做单独使用实现类 IPropertyEditorValueConverter
接口。在这里看到更多的信息:
If you then need to convert the selected ID into a Facility
object, do this separately using a class implementing the IPropertyEditorValueConverter
interface. See here for more information:
<一个href=\"http://our.umbraco.org/documentation/extending-umbraco/Property-Editors/PropertyEditorValueConverters\" rel=\"nofollow\">http://our.umbraco.org/documentation/extending-umbraco/Property-Editors/PropertyEditorValueConverters
这篇关于一把umbraco:创建与MVC模式prevalues的CheckBoxList财产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!