Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more

How to pass the Page type properties data to another class instance???

Vote:
 

Hi Guys,

     Icreated one page type with two properties like,

namespace EPIFind.Models.Pages

{
    [ContentType(DisplayName = "Home", GUID = "b48b974b-15f1-4fc5-8885-594ac465d932", Description = "")]
    public class Home : PageData
   {

       [CultureSpecific]

       [Display(
       Name = "Heading",
       Description = "",
       GroupName = SystemTabNames.Content,
       Order = 1)]

       public virtual string Heading { get; set; }

       [CultureSpecific]

       [Display(
       Name = "Count",
       Description = "",
       GroupName = SystemTabNames.Content,
       Order = 2)]

       public virtual int Count { get; set; }

}

i called this properties in .cshtml  and i gave the data from user interface to properties, now my requirement is how to pass this pagetype properties data to normal class properties, this is my class

namespace EPIFind.Models
{
    public class MyClass
    {
     public string Heading{ get; set; }
     public int count{ get; set; }
   }
}

 please guys can any one help me out of this.

Thanks,

Ramkee.G

#179019
May 29, 2017 16:52
Vote:
 

I would just assign it one by one or you can setup some lib (AutoMapper for example) that will do it automatically.

#179021
May 30, 2017 1:29
Vote:
 

Hi Valdis lljuconoks,

     Thanks for reply, can you provide any referance code for better understanding?

Thanks,

Kartheek

#179023
May 30, 2017 5:35
Vote:
 

I you are passing values to "normal class" in your controller, then it's pretty easy:

public ActionResult Index(Home currentPage)
{
    var instance = new MyClass();

    instance.Heading = currentPage.Heading;
    instance.count = currentPage.Count;

    ...
}
#179031
May 30, 2017 8:25
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.