如何实施投票系统?
我需要实现类似于 SO 投票的功能。我尝试查找围绕该主题的一些现有问题,发现大多数人都被如何投票赞成和反对所困扰。我已经过去了。我的问题是投票后如何处理。这就是我到目前为止所做的。
- 每个答案都会显示赞成票、反对票和分数。
- 用户点击时投票数发生变化 向上或向下并且图像更新 因此。
- 类似将信息保存在db中。 WHO 已投票、投票时间、投票类型、 userIP、ansID 等。
现在是问题。
- 我正在使用 gridview 来显示信息。如何在下一页加载时显示之前投票的答案。我在数据库中有信息,但我想在不影响性能的情况下执行此操作。我可以在 itemDatabound 事件中执行此操作,但它看起来不是一个很好的处理方法。我想知道是否有更好的方法来处理这种情况
- 切换投票:当用户切换 投票,背后发生了什么 场景。是之前投票的 记录删除与否?我说 应该删除但想要一个 确认。
- gridview是一个很好的实现方式吗 有这样的功能吗?
I am required to implement a functionality similar to SO voting. I tried to look up some existing questions around this topic and noticed that most people are stuck with how to vote up and down. i am past that. my problem is related to how to handle after a vote has been upvoted. here is what i have done till now.
- Vote up, Down and Score displayed for each answer.
- Vote count changed when user clicks
up or down and the image is updated
accordingly. - Save the information in db like. who
voted, time of vote, type of vote,
userIP, ansID, etc.
Now the questions.
- I am using a gridview to display information. how do i show the previously voted answers as voted on next page load. I have the information in db but i want to do this without affecting performance. I could do it in itemDatabound event but it doesnt look like a pretty way to handle it. i wonder if there is a better way to handle such situation
- Toggle Votes : When a user toggles a
vote, what happens behind the
scenes. is the previous upvoted
record deleted or not? i say it
should be deleted but want a
confirmation. - Is gridview a good way to implement
such functionality or not?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
1
)如果你使用的是gridview,你几乎必须采取这条路线。但我们需要有关您正在尝试做什么的更多详细信息。
2)当您对同一答案/问题投赞成票然后投反对票时,应检查并删除该答案/问题。请记住,您只能对问题或答案投票 1 票,因此您的数据库表应该编写为用户 ID、问题 ID 的唯一行(假设问题是唯一的)。因此,您甚至不应该允许它在表中插入重复的行。
3)stackoverflow是mvc类型的应用程序,您使用的是webforms,因此您可以使用gridview或listview。他们可能只是循环遍历答案并生成 html(因为这是 MVC)。
For
1) If you are using a gridview you almost have to take this route. But we need more details about what you are trying to do.
2) When you upvote and then downvote that same answer / question it should be checked and deleted. Remember you are only allowed 1 vote for a question or answer so your database table should be written so that their is a unique row for a userID, a QuestionID (given that a question is unique). So you should not even allow it to insert duplicate rows in a table.
3)stackoverflow is mvc type app, you are using webforms, so you could use a gridview or a listview. They are probably just looping through the answers and generating the html (as this is MVC).