Widget not displayed on front end

Topics: Writing modules
Mar 25, 2013 at 3:39 PM
Hi Team,
I have to developed one Contact Us from with custom dropdown list into it. To achive this requirement I have created one module. Here my problem is that when I add this as widget on page, it is not displaying on front end.
Please suggest.

My code for module as

Model:


public class ContactUsPart : ContentPart<ContactUsPartRecord>
{
    public int Id
    {
        get { return Record.Id; }
        set { Record.Id = value; }
    }

    public string FirstName
    {
        get { return Record.FirstName; }
        set { Record.FirstName = value; }
    }

    public string LastName
    {
        get { return Record.LastName; }
        set { Record.LastName = value; }
    }

    public string Email
    {
        get { return Record.Email; }
        set { Record.Email = value; }
    }

    public string State
    {
        get { return Record.State; }
        set { Record.State = value; }
    }

    public string RequestType
    {
        get { return Record.RequestType; }
        set { Record.RequestType = value; }
    }

    public string Comment
    {
        get { return Record.Comment; }
        set { Record.Comment = value; }
    }
}

public class ContactUsPartRecord : ContentPartRecord
{
    public virtual int Id { get; set; }
    public virtual string FirstName { get; set; }
    public virtual string LastName { get; set; }
    public virtual string Email { get; set; }
    public virtual string State { get; set; }
    public virtual string RequestType { get; set; }
    public virtual string Comment { get; set; }
}

Handlers

namespace CT_LienSolutions.ContactUs.Handlers
{
public class ContactUsHandler : ContentHandler
{
    public ContactUsHandler(IRepository<ContactUsPartRecord> repository)
    {
        Filters.Add(StorageFilter.For(repository));
    }
}
}

Drivers

using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement;
using CT_LienSolutions.ContactUs.Models;

namespace CT_LienSolutions.ContactUs.Drivers
{
public class ContactUsDriver : ContentPartDriver<ContactUsPart> 
{       
    protected override DriverResult Display(ContactUsPart part, string displayType, dynamic shapeHelper) 
    {
        //
        //return ContentShape("Parts_Product", () => shapeHelper.Parts_Product(Sku: part.Sku, Price: part.Price));

        ContactUsPart viewModel = new ContactUs.Models.ContactUsPart();            

        return ContentShape("Parts_ContactUsDataGallery",
                            () => shapeHelper.DisplayTemplate(
                                TemplateName: @"\DisplayTemplates\Parts\ContactUsForm.cshtml",//"Parts/ImageGallery",
                                Model: viewModel,
                                Prefix: Prefix));
    }
}
}


___Pleacement.info

<Placement>
<Place Parts_ImageGallery="Content:after"/>
<Place Parts_ImageGallery_Edit="Content:2.5"/>
</Placement>

Views

@using System.Web.Mvc.Html

@model CT_LienSolutions.ContactUs.Models.ContactUsPartRecord
<div class="contactUsForm"> <form method="" action=""> <h3 class="contactUsHeader"> Contact Us</h3> <div class="row"> @Html.TextBoxFor(m =>m.FirstName) </div> <div class="row"> @Html.TextBoxFor(m =>m.LastName) </div> <div class="row"> @Html.TextBoxFor(m =>m.Email) </div> <div class="row selectBoxBg"> <div class="selectValue"> State</div> <select class="stateSelectBox"> <option>State</option> <option>State 1</option> <option>State 2</option> <option>State 3</option> <option>State 4</option> </select> </div> <div class="row selectBoxBg"> <div class="selectValue"> Type of Request</div> <select class="requestTypSelectBox"> <option>Type of Request</option> <option>Type of Request 1</option> <option>Type of Request 2</option> <option>Type of Request 3</option> <option>Type of Request 4</option> </select> </div> <div class="row"> @Html.TextBoxFor(m =>m.FirstName) </div> <div class="row"> <input width="66" height="25" type="image" class="submitTyp" title="SUBMIT" src="images/submit.png"> <span class="contactCallInfo">or call 800.833.5778 </span> </div> </form> </div> Migration

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Orchard.Data.Migration;
using System.Data;
using Orchard.ContentManagement.MetaData;
using Orchard.Core.Contents.Extensions;

namespace CT_LienSolutions.ContactUs
{
public class Migrations :  DataMigrationImpl {
    public int Create()
    {
       SchemaBuilder.CreateTable("ContactUsData", table => table
                .Column<int>("Id", column => column.PrimaryKey().Identity())
                .Column<string>("FirstName", column => column.WithLength(255))
                .Column<string>("LastName", column => column.WithLength(255))
                .Column<string>("Email", column => column.WithLength(255))
                .Column<string>("State", column => column.WithLength(255))
                .Column<string>("RequestType", column => column.WithLength(255))
                .Column<string>("Comment", column => column.WithLength(5000))
            );

        return 1;
    }

    public int UpdateFrom1()
    {
        //ContentDefinitionManager.AlterTypeDefinition("ContactUsWidget", cfg => cfg
        //    .WithPart("ImageGalleryPart")
        //    .WithPart("WidgetPart")
        //    .WithPart("CommonPart")
        //    .WithSetting("Stereotype", "Widget"));

        ContentDefinitionManager.AlterTypeDefinition("ContactUsDataGallery", cfg => cfg
         //.WithPart("ImageGalleryPart")
         .WithPart("WidgetPart")
         .WithPart("CommonPart")
         .WithSetting("Stereotype", "Widget"));

        return 2;
    }
}
}
Mar 25, 2013 at 5:14 PM
Hi joshipavanr,

There´s a quite recent module in the gallery that could serve as a starting point for your development:

http://gallery.orchardproject.net/List/Modules/Orchard.Module.PlanetTelex.ContactForm

the source code is in codeplex:

http://orchardcontactform.codeplex.com/SourceControl/changeset/view/354e420805ec

This module exposes a simple contact form as a widget. You could fork this project and change it by adding the form fields that suit you needs.

Nuno Duarte.
Mar 26, 2013 at 2:34 PM
Hi,
Thanks for response and now I am able to solve my poblem.

But still I am wondering why my overridden Display method in driver not getting call to render (view) on front end. Please suggest reason for the same. Because I have some other custom functionality and I am not able to display it on front end.

Please reply because this is very important for me and my project delivery.
Developer
Mar 26, 2013 at 3:10 PM
Perhaps anything in the log files in App_data/Logs?
Mar 28, 2013 at 6:31 AM
Nothing in Logs.
Mar 28, 2013 at 2:55 PM
Hi,
I am now able to display view on front end when I have added ViewModel folder and class for the same.