First of all, I want to clarify that I'm just learning ASP MVC and Umbraco :). There may be very novice mistakes. I'm trying to make a system of interviews. Searching the Internet, I found an example I changed my taste. I created an empty project for testing, and this is all I have.
Umbraco admin
DocumentTypes
Answer // --> Without template (for the moment) - No have properties (for the moment)
Poll // --> Without template (for the moment) - No have properties (for the moment) - Have many "Answer" child and "Active" bool property
Polls // --> Without template (for the moment) - No have properties (for the moment) - Have many "Poll" child
PartialView
Polls
namespace Polls.Controllers
{
public class PollsController : SurfaceController
{
[HttpPost]
public ActionResult Submit(PollViewModel model)
{
// Do something...
return RedirectToCurrentUmbracoPage();
}
public ActionResult Index()
{
var testPage = Umbraco.Content(CurrentPage.Id);
var questions = new List<PollViewModel>();
foreach (var currentPoll in testPage.Where("Active"))
{
questions.Add(new PollViewModel { ID = currentPoll.ID, Title = currentPoll.Name.ToString(), Answers = AnswerList(currentPoll.ID) });
}
return PartialView("~/Views/Polls.cshtml", questions);
}
private List<Answer> AnswerList(int myQuestionID)
{
var questionPage = Umbraco.Content(myQuestionID);
var answers = new List<Answer>();
foreach (var currentAnswer in questionPage.Children)
{
answers.Add(new Answer { ID = currentAnswer.ID, Text = currentAnswer.Name.ToString() });
}
return answers;
}
}
}
Model
namespace Polls.Models
{
public class Answer
{
public int ID { get; set; }
public string Text { get; set; } // --> No use for now
}
}
namespace Polls.Models
{
public class PollViewModel
{
public int ID { get; set; }
public string Title { get; set; } // --> No use for now
public List<Answer> Answers { get; set; }
}
}
Issue with custom SurfaceController
First of all, I want to clarify that I'm just learning ASP MVC and Umbraco :). There may be very novice mistakes. I'm trying to make a system of interviews. Searching the Internet, I found an example I changed my taste. I created an empty project for testing, and this is all I have.
Umbraco admin
Umbraco content
In Visual Studio
SurfaceController
Model
PartialView "Polls"
Error (When I try to compile the solution)
Second question
How do I filter children by custom bool property? "Poll" DocumentType have a "Active" bool property.
This is correct?
THX!!!!
I fixed the problem, conflict was giving the name of the solution, but now have a new problem. It is very common, but can not find the solution.
Hi
Quick fix for this is to upgrade to 7.4.3. Had a similar problem with RenderModel
/Paul S
Maby it will help you solve problem: http://24days.in/umbraco/2014/working-with-complex-archetype-datatypes/
is working on a reply...