如果数据库中不存在UserId,我想显示“找不到配置文件”消息。我该如何实现它。以下代码不起作用。
UserId = Request.QueryString["UserId"];
var db = Database.Open("mystring");
var selectCommand = "SELECT * FROM UserProfile WHERE UserId = @0";
var row = db.QuerySingle(selectCommand, UserId);
if (row != null)
{
Email = row.Email;
fullname = row.fullname;
about = row.about;
}else{
ModelState.AddFormError("No Profile Found.");
}
答案 0 :(得分:0)
试试这样:
@{
var userId = Request.QueryString["UserId"];
var db = Database.Open("mystring");
var selectCommand = "SELECT * FROM UserProfile WHERE UserId = @0";
var row = db.QuerySingle(selectCommand, UserId);
}
@if (row != null) {
<div>
Email: @row.Email
</div>
<div>
Fullname: @row.fullname
</div>
<div>
About: @row.about
</div>
} else {
<div>No Profile Found.</div>
}