Has anybody had any experience of creating a poll in Contour and using Razor for users to vote and see results?
I've seen the example here http://www.nibble.be/?p=81 but this is XSLT. I think I could adapt this but wanted to see if anybody had done anything similar before?
Since COntour v3 there is a razor render of the form so you should be able to use that voting
TO display the results, that should be even easier then xslt, just change the code for the xslt extension (didn't test this just changed it here without testing)
@{ FormStorage fs = new FormStorage();
Form f = fs.GetForm(new Guid(guid));
fs.Dispose();
}
@foreach (Field fld in f.AllFields)
{
if (fld.FieldType.SupportsPrevalues
&& fld.PreValueSource.Type.GetPreValues(fld).Count > 0)
{ <h3>fld.Caption</h3>
<ul>
@foreach (PreValue pv in fld.PreValueSource.Type.GetPreValues(fld))
{ <li>pv.Value</li>
} </ul>
}
}
You'll just need some extra code to calc the amount of times an option is chosen
Thanks for the reply. I've got that working now so a poll is displaying when you've not already voted but doesn't displays when you have. I've got it creating and checking for the cookie.
I've tweaked your code above so it outputs the options but how do I get number of votes each option has? In your XSLT code you use "umbraco.contour:GetRecordsFromForm" but I'm unsure of the Razor equivalent. I'm guessing I need to pass in the PreValue in the for loop into a method to get the number of results?
Creating a poll using Razor
Hi
Has anybody had any experience of creating a poll in Contour and using Razor for users to vote and see results?
I've seen the example here http://www.nibble.be/?p=81 but this is XSLT. I think I could adapt this but wanted to see if anybody had done anything similar before?
Thanks!
Ben
Comment author was deleted
Hi Ben,
Since COntour v3 there is a razor render of the form so you should be able to use that voting
TO display the results, that should be even easier then xslt, just change the code for the xslt extension (didn't test this just changed it here without testing)
You'll just need some extra code to calc the amount of times an option is chosen
Hi Tim
Thanks for the reply. I've got that working now so a poll is displaying when you've not already voted but doesn't displays when you have. I've got it creating and checking for the cookie.
I've tweaked your code above so it outputs the options but how do I get number of votes each option has? In your XSLT code you use "umbraco.contour:GetRecordsFromForm" but I'm unsure of the Razor equivalent. I'm guessing I need to pass in the PreValue in the for loop into a method to get the number of results?
Thanks
Ben
Comment author was deleted
The same method is available from razor and returns dynamic objects
Umbraco.Forms.Mvc.DynamicObjects.Library
http://our.umbraco.org/projects/umbraco-pro/contour/documentation/Developer/Working-with-Contour-data-in-Razor/
You should then be able to use a where clause like is available on dynamicnode in umbraco
Don't know the syntax by heart but I'll give it a try
Comment author was deleted
Ok try the following:
Comment author was deleted
It just adds the amount of times an option has been voted for, to add percentage count the total ammount of records first ...
I was coding the same but your method looks a lot slicker than the route mine was going.
Thank you so much for your help, works perfectly! I'll finish off the percentages etc.
Comment author was deleted
No prob, glad it works now :)
is working on a reply...