我有一个问题,我使用Paging,它没有使用简单过滤器过滤,但是当数据来自高级搜索时,我得到以下错误:
传递到字典中的模型项的类型为'System.Collections.Generic.List'1 [WomenNew.Models.News_]',但此字典需要类型为'PagedList.IPagedList'1 [WomenNew。 Models.News _]”。
如果我可以在没有sql字符串和存储过程的情况下创建我的高级搜索(我在下面解释我的代码)我的问题将得到解决,或者如果我可以转换我的import pygame, random, os, sys
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
BLUE = (0, 0, 255)
GREEN = (0, 255, 0)
RED = (255, 0, 0)
PURPLE = (255, 0, 255)
YELLOW = (255, 200, 0)
GREY = (100, 100, 100)
pygame.init()
screen = pygame.display.set_mode((480, 320))
font = pygame.font.SysFont("Calibri", 50)
help_font = pygame.font.SysFont("Calibri", 30)
title_font = pygame.font.SysFont("Segoe", 150)
menu_font = pygame.font.Font(None, 80)
currentLevel = 0
pygame.display.set_caption("Amazeing Race")
screen = pygame.display.set_mode((1024, 768))
clock = pygame.time.Clock()
class Player(object):
def __init__(self, pos):
self.rect = pygame.Rect(pos[0], pos[1], 27, 27)
def move(self, dx, dy):
if dx != 0:
self.move_single_axis(dx, 0)
if dy != 0:
self.move_single_axis(0, dy)
def move_single_axis(self, dx, dy):
self.rect.x += dx
self.rect.y += dy
for wall in walls:
if self.rect.colliderect(wall.rect):
if dx > 0:
self.rect.right = wall.rect.left
if dx < 0:
self.rect.left = wall.rect.right
if dy > 0:
self.rect.bottom = wall.rect.top
if dy < 0:
self.rect.top = wall.rect.bottom
class Wall(object):
def __init__(self, pos):
self.rect = pygame.Rect(pos[0], pos[1], 41, 31)
class Finish1(object):
def __init__(self, pos):
Finish1.rect = pygame.Rect(pos[0], pos[1], 41, 31)
class Finish2(object):
def __init__(self, pos):
Finish2.rect = pygame.Rect(pos[0], pos[1], 41, 31)
class Finish3(object):
def __init__(self, pos):
Finish3.rect = pygame.Rect(pos[0], pos[1], 41, 31)
class Finish4(object):
def __init__(self, pos):
Finish4.rect = pygame.Rect(pos[0], pos[1], 41, 31)
class Option:
hovered = False
def __init__(self, text, pos):
self.text = text
self.pos = pos
self.set_rect()
self.draw()
def draw(self):
self.set_rend()
screen.blit(self.rend, self.rect)
def set_rend(self):
self.rend = menu_font.render(self.text, True, self.get_color())
def get_color(self):
if self.hovered:
return (WHITE)
else:
return (GREY)
def set_rect(self):
self.set_rend()
self.rect = self.rend.get_rect()
self.rect.topleft = self.pos
options = [Option("Easy", (450, 205)), Option("Medium", (450, 305)),
Option("Hard", (450, 405)), Option("Help", (450, 505)), Option("Exit", (450, 605))]
levels = [[
"WWWWWWWWWWWWWWWWWWWWWWWWW",
"WFW W GW",
"W W WWW W WWW W W WWW WWW",
"W W W W W W W",
"W WWWWW WWWWW W W WWWWW W",
"W W W W W W W W",
"W WWWWW W WWWWWWW W W W W",
"W W W W W W W W",
"WWWWW WWWWW WWW W W W W W",
"W W W W W W W W W",
"W WWW W WWW W WWWWWWW W W",
"W W W W W",
"W WWWWW WWWWP WWW W WWW W",
"W W W W W",
"W WWWWWWWWW W W WWW WWWWW",
"W W W W W W",
"WWWWWWW W WWW W WWWWWWW W",
"W W W W W W W W",
"WWW W WWW W WWW W WWW W W",
"W W W W W W W",
"WWWWW W WWW W W WWW W WWW",
"W W W W W W W",
"W W WWWWW WWWWW WWWWWWW W",
"WHW W WIW",
"WWWWWWWWWWWWWWWWWWWWWWWWW",
],
[
"WWWWWWWWWWWWWWWWWWWWWWWWW",
"WFW W W GW",
"W W WWW W WWW W W WWW WWW",
"W W W W W W W",
"W WWWWW WWWWW W W WWWWW W",
"W W W W W W W W",
"W WWWWW W WWWWWWW W W W W",
"W W W W W W W W",
"WWWWWWWWWWW WWW W W W W W",
"W W W W W W W W",
"W WWW W WWW W WWWWWWW W W",
"W W W W W",
"WWWWWWW WWWWP WWW W WWW W",
"W W W W W",
"W WWWWWWWWW W W WWW WWWWW",
"W W W W W W",
"WWWWWWW W WWW W WWWWWWW W",
"W W W W W W W W",
"WWW W WWW W WWW W WWW W W",
"W W W W W W W W",
"WWWWW W WWWWW W WWW W WWW",
"W W W W W W W",
"W W WWWWW WWWWW WWWWWWW W",
"WHW W WIW",
"WWWWWWWWWWWWWWWWWWWWWWWWW",
],
[
"WWWWWWWWWWWWWWWWWWWWWWWWW",
"WFW W W W GW",
"W W WWW W WWW W W WWW WWW",
"W W W W W W W",
"W WWWWW WWWWW W W WWWWW W",
"W W W W W W W W",
"W WWWWW W WWWWWWW W W W W",
"W W W W W W W W",
"WWWWWWWWWWW WWW W W W W W",
"W W W W W W W W",
"W WWW W WWW W WWWWWWW W W",
"W W W W W",
"WWWWWWW WWWWP WWW W WWW W",
"W W W W W",
"W WWWWWWWWW W W WWW WWWWW",
"W W W W W W",
"WWWWWWW W WWW W WWWWWWW W",
"W W W W W W W W W",
"WWW W WWW W WWW W W W W W",
"W W W W W W W W",
"WWWWW W WWWWW W WWW W WWW",
"W W W W W W W",
"W W WWWWW WWWWW WWWWWWW W",
"WHW W WIW",
"WWWWWWWWWWWWWWWWWWWWWWWWW",
]]
def load_level(level):
walls = []
players = []
finishes = []
x = y = 0
for row in levels[level]:
for col in row:
if col == "W":
walls.append(Wall((x, y)))
if col == "P":
players.append(Player((x, y)))
if col == "F":
finishes.append(Finish1((x, y)))
if col == "G":
finishes.append(Finish2((x, y)))
if col == "H":
finishes.append(Finish3((x, y)))
if col == "I":
finishes.append(Finish4((x, y)))
x += 40.96
y += 30.72
x = 0
return walls, players, finishes
walls, players, finishes = load_level(currentLevel)
def Menu():
global currentlevel, walls, players, finishes
runnin = True
while runnin:
clock.tick(60)
screen.fill(BLACK)
mouseclick = pygame.mouse.get_pressed()
for e in pygame.event.get():
if e.type == pygame.QUIT:
pygame.quit()
sys.exit(0)
if e.type == pygame.KEYDOWN:
if e.key == pygame.K_ESCAPE:
pygame.quit()
sys.exit(0)
for option in options:
if option.rect.collidepoint(pygame.mouse.get_pos()):
option.hovered = True
if mouseclick[0] == 1:
if option.text == "Easy":
walls, players, finishes = load_level(0)
currentlevel = 0
main()
elif option.text == "Medium":
walls, players, finishes = load_level(1)
currentlevel = 1
main()
elif option.text == "Hard":
walls, players, finishes = load_level(2)
currentlevel = 2
main()
elif option.text == "Help":
Help()
else:
runnin = False
else:
option.hovered = False
option.draw()
screen.blit(title_font.render("A-maze-ing Race", True, GREY), (100, 50))
pygame.display.update()
pygame.quit()
sys.exit(0)
def Help():
runnin = True
option = Option("Back", (20, 700))
while runnin:
clock.tick(60)
screen.fill(BLACK)
mouseclick = pygame.mouse.get_pressed()
for e in pygame.event.get():
if e.type == pygame.QUIT:
pygame.quit()
sys.exit(0)
if e.type == pygame.KEYDOWN:
if e.key == pygame.K_ESCAPE:
pygame.quit()
sys.exit(0)
if option.rect.collidepoint(pygame.mouse.get_pos()):
option.hovered = True
if mouseclick[0] == 1:
if option.text == "Back":
Menu()
else:
option.hovered = False
option.draw()
screen.blit(help_font.render("First, select a level: Easy, Medium, or Hard", True, WHITE), (10, 20))
screen.blit(help_font.render("Easy - More manoeverable map, no sight restrictions.", True, WHITE), (10, 50))
screen.blit(help_font.render("Medium - More constricted map, vision of walls disappears after 8 seconds.", True, WHITE), (10, 80))
screen.blit(help_font.render("Hard - Slighty different and constricted map layout, vision of walls disappears after", True, WHITE), (10, 110))
screen.blit(help_font.render("3 seconds.", True, WHITE), (10, 140))
screen.blit(help_font.render("Once in the level you will have 10 seconds to prepare before one of the 4 green", True, WHITE), (10, 180))
screen.blit(help_font.render("blocks in the corner turns red and the countdown starts. Then you must navigate", True, WHITE), (10, 210))
screen.blit(help_font.render("through the maze and reach the red block before the time runs out. If you", True, WHITE), (10, 240))
screen.blit(help_font.render("reach the red block in time when the timer started at 10 seconds then you win ", True, WHITE), (10, 270))
screen.blit(help_font.render("the game.", True, WHITE), (10, 300))
pygame.display.update()
def main():
option = Option("Menu", (78, 697))
pygame.display.update()
rand = random.randint(1, 4)
frame_count = 0
frame_rate = 60
start_time = 50
prep_time = 10
best_time = 400
if currentlevel == 1:
show_time = 7 + prep_time
else:
show_time = 3 + prep_time
total_seconds = 50
show_seconds = 25
running = True
while running:
mouseclick = pygame.mouse.get_pressed()
prep_seconds = prep_time - (frame_count // frame_rate)
minutes = prep_seconds // 60
seconds = prep_seconds % 60
output_string = "Preparation time: {0:02}:{1:02}".format(minutes, seconds)
if prep_seconds < 0:
show_seconds = show_time - (frame_count // frame_rate)
total_seconds = start_time - (frame_count // frame_rate)
minutes = total_seconds // 60
seconds = total_seconds % 60
output_string = "Time left: {0:02}:{1:02}".format(minutes, seconds)
if total_seconds > 0:
frame_count += 1
clock.tick(frame_rate)
for e in pygame.event.get():
if e.type == pygame.QUIT:
running = False
if e.type == pygame.KEYDOWN and e.key == pygame.K_ESCAPE:
running = False
option.hovered = True
if option.rect.collidepoint(pygame.mouse.get_pos()):
if mouseclick[0] == 1:
if option.text == "Menu":
Menu()
key = pygame.key.get_pressed()
if total_seconds > 0:
if key[pygame.K_LEFT]:
player.move(-3, 0)
if key[pygame.K_RIGHT]:
player.move(3, 0)
if key[pygame.K_UP]:
player.move(0, -3)
if key[pygame.K_DOWN]:
player.move(0, 3)
for player in players:
if player.rect.colliderect(Finish1.rect) and rand == 1 or player.rect.colliderect(Finish2.rect) and rand == 2 or player.rect.colliderect(Finish3.rect) and rand == 3 or player.rect.colliderect(Finish4.rect) and rand == 4:
if prep_seconds < 0:
show_seconds = 25
frame_count = 0
if total_seconds < best_time:
best_time = start_time - prep_time - total_seconds
prep_seconds = prep_time - (frame_count // frame_rate)
minutes = prep_seconds // 60
seconds = prep_seconds % 60
output_string = "Preparation time: {0:02}:{1:02}".format(minutes, seconds)
start_time -= 10
rand = random.randint(1, 4)
screen.fill(BLACK)
if currentlevel == 2 or currentlevel == 1:
if show_seconds > 0:
for wall in walls:
pygame.draw.rect(screen, (GREY), wall.rect)
else:
for wall in walls:
pygame.draw.rect(screen, (GREY), wall.rect)
pygame.draw.rect(screen, (GREEN), Finish1.rect)
pygame.draw.rect(screen, (GREEN), Finish2.rect)
pygame.draw.rect(screen, (GREEN), Finish3.rect)
pygame.draw.rect(screen, (GREEN), Finish4.rect)
if prep_seconds < 0:
if rand == 1:
pygame.draw.rect(screen, (RED), Finish1.rect)
elif rand == 2:
pygame.draw.rect(screen, (RED), Finish2.rect)
elif rand == 3:
pygame.draw.rect(screen, (RED), Finish3.rect)
else:
pygame.draw.rect(screen, (RED), Finish4.rect)
for player in players:
pygame.draw.rect(screen, (YELLOW), player.rect)
screen.blit(font.render(output_string, True, GREEN), (350, 700.04))
if start_time == 10:
screen.fill(BLACK)
prep_seconds = 0
total_seconds = 0
minutes = 0
seconds = 0
screen.blit(font.render("YOU WIN", True, GREEN), (440, 500))
screen.blit(font.render("Your best time was " + str(best_time)+" seconds", True, GREEN), (260, 600))
screen.blit(font.render("Click to return to the Main Menu", True, GREEN), (250, 700))
if mouseclick[0] == 1 or mouseclick[1] == 1:
running = False
elif total_seconds < 0.1:
screen.fill(BLACK)
prep_seconds = 0
total_seconds = 0
minutes = 0
seconds = 0
screen.blit(font.render("YOU LOSE", True, GREEN), (440, 500))
if best_time == 400:
screen.blit(font.render("You did not touch a block.", True, GREEN), (280, 600))
else:
screen.blit(font.render("Your best time was " + str(best_time)+" seconds", True, GREEN), (260, 600))
screen.blit(font.render("Click to return to the Main Menu", True, GREEN), (250, 700))
if mouseclick[0] == 1 or mouseclick[1] == 1:
running = False
option.draw()
pygame.display.flip()
Menu()
它会很好,我的更改将会很少< / p>
我的控制器高级搜索是:
object List<News_>
如果TempData [“news_List”]不为null,则对象传递给Index视图[HttpGet]如果我可以在Index中创建不同的参数,如下代码:
public ActionResult AdvanceSearch_(string DateSFrom, string DateSTo, string Export, string Media, string issue, string subject, string society, string official, string details, string details2, string details3)
{
// create object
List < News_ > newsList_ = new List<News_>();
if (!string.IsNullOrEmpty(details))
{
strQuery2 = "(Details like N'%" + details + "%')";
}
// here other parameter of search is created:
if (!string.IsNullOrEmpty(Media))
{
strQuery2 += "(Media like N'%" + CommonClass.Cpersian(Media) + "%')";
}
// here deferment parameters are joint
strQuery2 = strQuery2.Replace(")(", ") and (");
//here with a stored procedure method object is filled
newsList_ = cmd.GetNewsList(strQuery);
if (newsList_.Count > 0)
{
TempData["news_List"] = newsList_;
if (Export == "Search")
return RedirectToAction("Index", "News_");
else
.........
但提前行动我不知道如何制作.... [HttpGet]
public ActionResult Index(string searchBy, string search, int? page)
{
if (TempData["news_List"] != null)
{
return View(TempData["news_List"]);
}
if (searchBy == "News")
{
return View(db.News_.Where(x => (x.Details.Contains(search)) ||
(x.Issue.Contains(search))).OrderByDescending(s => s.Id).ToList().ToPagedList(page ?? 1,3));
或如何传递到索引视图
我的观点是:
x => (x.Details.....
我更愿意转换为将@using PagedList;
@using PagedList.Mvc;
@model IPagedList<WomenNew.Models.News_>
转换为List< News_> newsList_ = new List<News_>();
,否则我必须更改我的预先搜索,但如果有必要,我会这样做。
答案 0 :(得分:0)
Stephen Muecke给了我正确的答案,他写信给我:
你需要转换TempData [“news_List”];在返回视图之前,您需要更改ActionIndex,如下所示: if(TempData [“news_List”]!= null) {var list = TempData [“news_List”]作为List; return view(list.ToPagedList(page ?? 1,3)); .....} 我很欣赏Stephen Muecke它为我节省了很多时间。托马斯
shareeditdeleteflag