执行以下代码时,我收到错误消息“Sequence contains no elements”:
public PartialViewResult access (string usern, string passw)
{
string pw;
var useraccess = (from check in myfirstDB.Users
where check.Name.Equals(usern)
select check).Single();
...
}
但是,如果我插入文字代替变量usern
,代码将按预期工作。我确定记录存在于我的表格中。我正在使用jquery这样调用控制器:
$('#access-form').click(function () {
$.ajax({
url: '/home/access',
contentType: 'application/html; charset=utf-8',
type: 'GET',
dataType: 'html'
})
.success(function (result) {
$('#access-field').html(result);
})
.error(function (xhr, status) {
alert(status);
})
});