0

i have 4 dto and i want to use it in cshtml. How do I call those 4 dto? tbCUserGuideSlugfContent,tbCUserGuideSlugDTO,fImageJSONResDTO,fImageJSONDTO

tbCUserGuideSlugfContent

 public class tbCUserGuideSlugDTO
    {
            public Nullable<Guid> fID { get; set; }
        public string fSlug { get; set; }
        public string fType { get; set; }
        public string fTitleID { get; set; }
        public string fTitleEN { get; set; }
        public string fTitleCN { get; set; }
        public tbCUserGuideSlugfContent fContentID { get; set; }
        public tbCUserGuideSlugfContent fContentEN { get; set; }
        public tbCUserGuideSlugfContent fContentCN { get; set; }
        public Nullable<Guid> fPdfIDKey { get; set; }
        public Nullable<Guid> fPdfENKey { get; set; }
        public Nullable<Guid> fPdfCNKey { get; set; }
        public string fActive { get; set; }
        public Nullable<Guid> fCreatedByID { get; set; }
        public DateTime fCreatedDate { get; set; }
        public Nullable<Guid> fLastModifiedByID { get; set; }
        public DateTime fLastModifiedDate { get; set; }
        public string fileBase64ID { get; set; }
        public string fileBase64EN { get; set; }
        public string fileBase64CN { get; set; }
        public bool reuploadPdfID { get; set; }
        public bool reuploadPdfEN { get; set; }
        public bool reuploadPdfCN { get; set; }
    }

tbCUserGuideSlugfContent

 public class tbCUserGuideSlugfContent
    {
        public string fTitle { get; set; }
        public string fBody { get; set; }
        public string fAttachment { get; set; }
        public fImageJSONDTO[] fImage { get; set; }
    }

fImageJSONResDTO

 public class fImageJSONResDTO
    {
        public string uri { get; set; }
        public int width { get; set; }
        public int height { get; set; }

    }

fImageJSONDTO

  public class fImageJSONDTO
    {
        public Guid id { get; set; }
        public fImageJSONResDTO high { get; set; }
        public fImageJSONResDTO med { get; set; }
        public fImageJSONResDTO low { get; set; }
        public fImageJSONResDTO thumbnailHigh { get; set; }
        public fImageJSONResDTO thumbnailMed { get; set; }
        public fImageJSONResDTO thumbnailLow { get; set; }
        public string text { get; set; }
        public string textPosition { get; set; }
    }

1 Answers1

0

First of all the 'M' at the MVC stands for Model, and in MVC pattern you should use Model key instead of 'DTO'.

You can merge this 'DTOs' in an another dto and use it in the .cshtml

    public class MyViewDto
    {
      public tbCUserGuideSlugDTO TbCUserGuideSlug { get; set;}

      public fImageJSONDTO FImageJson {get;set;}
      
      public fImageJSONResDTO FImageJSONRes {get;set;}

      public tbCUserGuideSlugfContent TbcUserGuideSlugfContent {get;set;}

   }

In your action you can create a new instance of 'MyViewDto' and return it to your .cshtml.

public IActionResult MyOperation(object myParameters)
{
   // Your service call or logic to get/create your Dtos.
   
  tbCUserGuideSlugDTO userGuideSlug = userGuideSlugService.GetGuideSlugByParameters(myParameters);
  fImageJSONDTO  fImageJson = imageService.GetFImageAsJsonByParameters(myParameters);
  fImageJSONResDTO = fImageJsonRes = imageService.GetFIMagenResAsJsonByParamaters(myParameters);
  tbCUserGuideSlugfContent =  tbcUserGuideSlugContent = userGuideSlugService.GetTbCUserGuideSlugfContentByParameters(myParameters);
   
  MyViewDto myDto = new MyViewDto(){
    TbCUserGuideSlug = userGuideSlug,
    FImageJson =  fImageJson,
    FImageJSONRes = fImageJsonRes,
    TbcUserGuideSlugfContent = tbcUserGuideSlugContent
  };
  // TODO: Return a view with myDto.
}

At your cshtml you can access the your 'DTO's with dot notation.

<label>Slug Content Title: </label> 
<label>@Model.TbCUserGuideSlug.fTitle</label>
ierhalim
  • 298
  • 3
  • 16