Asp.net Razor搜索问题 [英] Asp.net Razor Searching Problem
本文介绍了Asp.net Razor搜索问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hello Everyone,
i我试图制作文本框谁从网站上的数据库中搜索数据。我仍然面临一个错误。
错误:编译器错误消息:CS1061:'string'不包含'Title'的定义,并且没有扩展方法'Title'可以找到接受'string'类型的第一个参数(你是否缺少using指令或汇编参考?)
。请参阅代码并告诉我问题出在哪里。
Hello Everyone,
i am Trying to Make TEXT Box Who Search data From The Database on Website.i am still Face One Error.
Error: "Compiler Error Message: CS1061: 'string' does not contain a definition for 'Title' and no extension method 'Title' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)"
.Please See the Code and tell me Where is The Problem.
@{
//var PostID=Request.QueryString["Postid"];<a href="Default.cshtml"></a>
int ID=0;
var Post="";
var PostID=Request.Form["Search"];
if(!PostID.IsEmpty() && PostID.IsInt())
{
ID=Convert.ToInt32(PostID);
}
var Db=Database.Open("Lesson1");
//var Post=Db.QuerySingle("Select * From BlogPosts Where ID=@0 And DatePublished<getdate()",ID);
Post=Db.QuerySingle("Select * From BlogPosts Where Id=@0 And DatePublished<getdate()",ID);
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<form action="" method="post">
<label for="Search">Search:</label>
<input type="search" placeholder="Enter Post ID" name="Search" value="">
<input type="submit" value="Submit">
</form>
@if(Post!=null)
{
<div>
<h1>@Post.Title</h1>
<p>@Html.Raw(Post.Content)</p>
</div>
}
else
{
<p>Not Blog Post Is Found</p>
}
</body>
</html>
推荐答案
您已将变量Post
声明为字符串
:
You've declared the variablePost
as astring
:
var Post="";
删除该行,并使用:
Remove that line, and use:
var Post = Db.QuerySingle("Select * From BlogPosts Where Id=@0 And DatePublished < getdate()", ID);
这篇关于Asp.net Razor搜索问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文