Jump to content

Check out our Community Blogs

Register and join over 40,000 other developers!

Recent Status Updates

View All Updates

- - - - -

How to allow users to create new polls with ASP.NET MVC 2?

asp.net mvc

  • Please log in to reply
2 replies to this topic

#1 misao


    CC Newcomer

  • Member
  • PipPip
  • 11 posts

Posted 28 October 2011 - 08:04 AM

For some reason I can't seem to wrap my head around this one. I want logged-in users to be able to create new pages (say, polls), then display a list of all the polls created with links that are available to all website visitors.

So I have the MVC stuff for the poll creation, they each have a unique id, but I don't know how to display the list of polls on the main page, which should increase with each poll created, and how to get each view to display a different poll. I have all of the poll objects in a List, but how do I set up my controller such that when each different link is clicked, the user goes to the appropriate view id which automatically displays the right poll? And what view should I make in that context?

In my controller I have

public ViewResult ViewPoll(string id)
            return View(id);

And in my main page view

            foreach (var poll in Poll.Models.PollsRepository.Get().polls)
           { %>

                <p><%= Html.ActionLink("Poll Number", "ViewPoll", new { id = poll })%> is open </p>
            <% }

Which throws this error when I click on them:

The view 'Poll.Models.PollModel' or its master was not found. The following locations were searched:

But did I not specifically tell the controller to go to the ViewPoll action in the links? Why is it still not searching there, and what am I missing?


Edited by Alyn, 30 October 2011 - 03:30 AM.
added code tag

  • 0

#2 BlackRabbit


    CodeCall Legend

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 3871 posts
  • Location:Argentina
  • Programming Language:C, C++, C#, PHP, JavaScript, Transact-SQL, Bash, Others
  • Learning:Java, Others

Posted 11 April 2012 - 05:30 AM

I would like to take a look to the code behind, but it looks like an initialization error,
why don't you show us some more code

in the other hand, you can use polldaddy for showing polls and pollresults, it would make your work easy
  • 0

#3 KineticShampoo


    CC Lurker

  • New Member
  • Pip
  • 7 posts
  • Location:Boston

Posted 19 April 2012 - 04:25 PM


<%= Html.ActionLink("Poll Number", "ViewPoll", new { id = poll })%>

Will generate something like this:

<a href="/YourController/ViewPoll/12">Poll Number</a>

And when you click it, it'll invoke your ActionMethod.

The error you are seeing is because you do not have a View named: ViewPoll

Show us a screenshot of your solution with only the Controllers and the Views folder expanded.
  • 0

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download