Linq工作不正常,没有在Ajax中获得任何数据



我有两个表,一个是"问题",第二个是"调查问题">

Questions has four column ID , Text, QuestionType, Options

SurveyQuestion has four column ID, SuerveyID , QuestionID, OrderID

我有调查ID,现在正试图使用LINQ并从问题表、中获取所有值

我从Ajax调用的方法在Controller中,也就是中

public ActionResult Index(string prefix)
{
List<SelectList> Questions = new List<SelectList>();
//  Here "MyDatabaseEntities " is dbContext, which is created at time of model creation.
SurveyAppEntities ObjectSur = new SurveyAppEntities();
// Questions = ObjectSur.Surveys.Where(a => a.ID.Equals(prefix)).toToList();
var e = from q in ObjectSur.Questions
join b in ObjectSur.SurveyQuestions on q.ID equals b.QuestionID
where b.SurveyID.Equals(prefix)
select q;
return Json(e, JsonRequestBehavior.AllowGet);
}

Ajax Cal和这个返回数据的方法工作得很好,因为我只尝试传递字符串,在更改该字符串后,我收到了Ajax警报,但当使用这个linq时,没有发送任何结果

希望你的建议

Ajax Call:
function MyFunction() {
alert($('#DDlSurvey').val());
$.ajax({
url: "@Url.Action("Index", "ConductSurvey")",
data: { prefix: $('#DDlSurvey').val() },
type: "POST",
dataType: "json",
success: function (data) {
//  loadData(data);
alert(data)
alert("Success");
},
error: function () {
alert("Failed! Please try again.");
}
});
//$('#YourLabelId').val('ReplaceWithThisValue');
}

我希望这将对您有所帮助。

var e = (from q in ObjectSur.Questions
join b in ObjectSur.SurveyQuestions on q.ID equals b.QuestionID
where b.SurveyID.Equals(prefix)
select q).ToList()

最新更新