2

我正在尝试编写一个查询来显示当前登录用户拥有的所有记录,但我在将“userid”变量插入字符串时遇到问题?

@{
Layout = "~/_template1.cshtml";
var db = Database.Open("StayInFlorida");


var userid = WebSecurity.CurrentUserId;
var premierproperty = "SELECT PropertyName, PropertyID FROM PropertyInfo WHERE OwnerID='userid'";
}

<h1>Properties - Page coming soon</h1>

@userid

@foreach (var row in db.Query(premierproperty)){
@row.propertyname
} 

有任何想法吗?

4

1 回答 1

3

试试这样:

@{
    Layout = "~/_template1.cshtml";
    var db = Database.Open("StayInFlorida");
    var userid = WebSecurity.CurrentUserId;
    var premierproperty = "SELECT PropertyName, PropertyID FROM PropertyInfo WHERE OwnerID = @0";
}

<h1>Properties - Page coming soon</h1>

@userid

@foreach (var row in db.Query(premierproperty, userid))
{
    @row.propertyname
} 
于 2013-03-01T15:28:35.623 回答