【发布时间】:2015-11-25 11:33:04
【问题描述】:
我想要的是,我想检查数据库中是否有文件。为此,我在控制器中有一个方法,它检查这个并为相应的情况返回一个布尔值。它看起来像这样:
public bool fileInDb(int empId)
{
using (SLADbContext db = new SLADbContext())
{
bool file = db.CompetenceUploads.Any(x => x.EmployeeId == empId);
if (file)
{
return true;
}
else
{
return false;
}
}
}
我只是检查是否有任何文件分配给给定的员工。
现在我想在视图中从我的 javascript 调用此方法,并获取返回值,这样我就可以让用户知道是否有文件分配给所选员工。它可能看起来像这样:
$("#get-file").click(function() {
empId: $("#EmployeeSelect").val();
var fileInDb = // Get the return value from the method 'fileInDb'
if(fileInDb) {
// Let the user download the file he/she requested
var url = "@Url.Action("GetUploadedFile", "Competence")";
this.href = url + '?empId=' + encodeURIComponent($("#EmployeeSelect").val());
} else {
alert("There is no file assigned to this employee.");
}
});
所以我现在的问题是,如何从控制器中的方法获取返回值?
【问题讨论】:
标签: javascript c# asp.net .net