Question

I am trying to write a query to show all records owned by the current logged on user but i am having issues inserting the "userid" variable into the string?

@{
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
} 

Any ideas?

Was it helpful?

Solution

Try like this:

@{
    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
} 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top