Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8784881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:12:50+00:00 2026-06-13T21:12:50+00:00

I created a content part, and add it to content type. When I create

  • 0

I created a content part, and add it to content type.
When I create content type, a content part is not displayed, unlike as other fields.
No have compilation or logged errors, content part added to placement.info.

Driver:

[UsedImplicitly]
public class TradeItemPartDriver: ContentPartDriver<TradeItemPart>
{
    private readonly ITradeItemService _tradeItemService;

    private const string TemplateName = "Parts/TradeItem";

    public TradeItemPartDriver(ITradeItemService tradeItemService)
    {
        _tradeItemService = tradeItemService;
    }

    protected override string Prefix
    {
        get { return "TradeItem"; }
    }

    protected override DriverResult Display(
        TradeItemPart part,
        string displayType,
        dynamic shapeHelper)
    {

        return ContentShape("Parts_TradeItem",
                        () => shapeHelper.Parts_TradeItem(
                            ContentPart: part)); 
    }

    protected override DriverResult Editor(
        TradeItemPart part,
        dynamic shapeHelper)
    {
        var shape = ContentShape("Parts_TradeItem_Edit",
                () => shapeHelper.EditorTemplate(
                    TemplateName: TemplateName,
                    Model: BuildEditorViewModel(part),
                    Prefix: Prefix));
        return shape;
    }

    protected override DriverResult Editor(
        TradeItemPart part,
        IUpdateModel updater,
        dynamic shapeHelper)
    {

        var model = new EditTradeItemViewModel();
        updater.TryUpdateModel(model, Prefix, null, null);

        if (part.ContentItem.Id != 0)
        {
            _tradeItemService.UpdateTradeItemForContentItem(
                part.ContentItem, model);
        }

        return Editor(part, shapeHelper);
    }

    private EditTradeItemViewModel BuildEditorViewModel(TradeItemPart part)
    {
        var model = new EditTradeItemViewModel
        {
Code = part.Code, Cost= part.Cost, Unit = part.Unit, Weight = part.Weight,
UnitsList = _tradeItemService.GetUnitTypes()
        };
        return model;
    }
}

Handler:

public class TradeItemPartHandler : ContentHandler
{
    public TradeItemPartHandler(IRepository<TradeItemPartRecord> repository)
    {
        Filters.Add(StorageFilter.For(repository));
    }
}

Models:

public enum EnumTradeItemUnit  : byte
{
    Шт = 0,
    Кг = 1,
    Литр = 2,
    Упаковка = 3
}

public class TradeItemPartRecord : ContentPartRecord
{
    public virtual string Code { get; set; }
    public virtual decimal Weight { get; set; }
    public virtual decimal Cost { get; set; }
    public virtual int Unit { get; set; }
}

public class TradeItemPart : ContentPart<TradeItemPartRecord>
{
    public virtual string Code { get; set; }
    public virtual decimal Weight { get; set; }
    public virtual decimal Cost { get; set; }
    public virtual EnumTradeItemUnit Unit { get; set; }
}

Serveces:

public interface ITradeItemService: IDependency
{
    //IEnumerable<TradeItemPart> GetTradeItems();
    SelectList GetUnitTypes();
    void UpdateTradeItemForContentItem(
        ContentItem item,
        EditTradeItemViewModel model);
}

public class TradeItemService : ITradeItemService
{
    private readonly IContentManager _contentManager;
    private readonly IRepository<TradeItemPartRecord> _tradeItemsRepository;

    public TradeItemService(IContentManager contentManager, IRepository<TradeItemPartRecord> tradeItemsRepository)
    {
        _contentManager = contentManager;
        _tradeItemsRepository = tradeItemsRepository;
    }

    public SelectList GetUnitTypes()
    {
        return new SelectList(
        Enum.GetValues(typeof(EnumTradeItemUnit)).Cast<EnumTradeItemUnit>().Select
            (it =>
            new SelectListItem() { Value = ((byte)it).ToString(), Text = it.ToString() }));
    }

     public void UpdateTradeItemForContentItem(
        ContentItem item,
        EditTradeItemViewModel model)
    {
        var part = item.As<TradeItemPart>();
        part.Code = model.Code;
        part.Cost = model.Cost;
        part.Unit = model.Unit;
        part.Weight = model.Weight;
    }
}

ViewModel:

public class EditTradeItemViewModel
{
    [StringLength(10), WebDisplayName("Код")]
    public virtual string Code { get; set; }
    [Required, Range(0, 100, ErrorMessage = "Товары тяжелее 100кг пусть более крутые ребята возят"), WebDisplayName("Вес")]
    public virtual decimal Weight { get; set; }
    [Required, Range(0.01, 100000, ErrorMessage = "Товары дороже 100тыс.р. пусть более крутые ребята возят"), WebDisplayName("Цена")]
    public virtual decimal Cost { get; set; }
    [Required, WebDisplayName("Единица измерения")]
    public virtual EnumTradeItemUnit Unit { get; set; }
    public virtual SelectList UnitsList { get; set; }
}

~/Views/EditorTemplates/Parts/TradeItem.cshtml

@model Delivery.ViewModels.EditTradeItemViewModel
<fieldset>
    <legend>@T("Характеристики")</legend>

  <div class="editor-label">
    @Html.LabelFor(model => model.Code, T("Код"))
  </div>
  <div class="editor-field">
    @Html.TextBoxFor(model => model.Code)
    @Html.ValidationMessageFor(model => model.Code)
  </div>

  <div class="editor-label">
    @Html.LabelFor(model => model.Unit, T("Единица измерения"))
  </div>
  <div class="editor-field">
    @Html.DropDownListFor(model => model.Unit, Model.UnitsList)
    @Html.ValidationMessageFor(model => model.Unit)
  </div>

  <div class="editor-label">
    @Html.LabelFor(model => model.Cost, T("Стоимость"))
  </div>
  <div class="editor-field">
    @Html.TextBoxFor(model => model.Cost)
    @Html.ValidationMessageFor(model => model.Cost)
  </div>

  <div class="editor-label">
    @Html.LabelFor(model => model.Weight, T("Вес одной единицы"))
  </div>
  <div class="editor-field">
    @Html.TextBoxFor(model => model.Weight)
    @Html.ValidationMessageFor(model => model.Weight)
  </div>

</fieldset>

Placement:

<Placement>
  <Place Parts_TradeItem_Edit="Content:10"/>
  <Place Parts_TradeItem="Content:10"/>
</Placement>

Migrations:

        SchemaBuilder.CreateTable("TradeItemRecord",
                       table => table
                           .ContentPartRecord()
                           .Column<string>("Code", column => column.WithLength(10))
                           .Column<decimal>("Weight", column => column.WithPrecision(8).WithScale(2))
                           .Column<decimal>("Cost", column => column.WithPrecision(8).WithScale(2))
                           .Column<byte>("Unit")
                       );

        ContentDefinitionManager.AlterPartDefinition("TradeItem",
            builder => builder.Attachable());
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T21:12:51+00:00Added an answer on June 13, 2026 at 9:12 pm

    There are generally 2 problems with your code.

    First, in your migrations, you called the part TradeItem while in the model, you called it TradeItemPart. Changing one or the other will solve the problem of why nothing is showing up in the editor.

    Which leads us to the second problem which will disable saving any of your data. You didn’t connect your TradeItemPart with your TradeItemPartRecord. To solve this problem, you’ll need to adjust TradeItemPart so that it looks like this:

    public class TradeItemPart : ContentPart<TradeItemPartRecord>
    {
        public string Code { 
            get { return Record.Code; } 
            set { Record.Code = value; } 
        }
        public decimal Weight { 
            get { return Record.Weight; } 
            set { Record.Weight = value; } 
        }
        public decimal Cost { 
            get { return Record.Cost; } 
            set { Record.Cost = value; } 
        }
        public EnumTradeItemUnit Unit { 
            get { return (EnumTradeItemUnit)Record.Unit; } 
            set { Record.Unit = (int)value; } 
        }
    }
    

    I’m also not sure whether Orchard will correctly associate column of type byte to the int type. If above mentioned changes don’t work, try changing the column type of Unit column to int.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created a content type which has some fields and i want this fields
i created an additional content type called clients where I can create new client
How can I achieve the following: I have created a content type called journal,
I created a new content type for a wiki page library. I added this
I have created a div with the ID 'tt-content', I want the div and
I have created my custom field type for listing available users in to Dropdownlist.
I have created a very basic service operation that needs to write content to
I'm using the following query: INSERT INTO role (name, created) VALUES ('Content Coordinator', GETDATE()),
Can I avoid forwarding after content is created / saved ? I don't want
I recently set up a local copy of Wordpress, added some content and created

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.