0
それを真に提供しなければならないように、それをすぐに私のjsonに送る。それが本当であるならば、それは成功のメッセージを作らなければなりません。しかし、それが適合しないならば、それは行かなければならず、誤りを与えなければならない。ユーザーに成功またはエラーメッセージを表示する必要があります。
今のところ問題は、成功したかエラーかを返す必要があることです。
あなたが書いたテキストだけでなく、時間に関して正しいか間違って問題を解決したかどうかを返信するだけです。
これは私がMVCでウェブサイトを構築した方法です。 ASP.net
<input type="hidden" ng-init="GetId='@Model.Id'" ng-model="GetId" />
<div ng-repeat="module in Newslist" style="clear:both; margin:7px 0; min-height:110px; margin:5px 0;">
<div class="col-md-8">
<div ng-show="Succes">
succes
</div>
<div ng-show="Error">
Error
</div>
<div style="clear:both; margin-bottom:10px;" class="col-md-10">
<input type="text" ng-model="module.text" class="form-control" placeholder="Write your answer here" name="Text" />
<button ng-click="CheckValue(module)" class="btn btn-primary pull-right" style="margin:6px 0;">
Check your answer
</button>
</div>
</div>
</div>
Load.js
var app = angular.module('Opgaver', []);
app.controller('OpgaverCheck', function ($scope, $http) {
$scope.CheckValue = function (module) {
//console.log("Hello world " + module.Id + " - " + module.text);
//POST
$scope.$watch("Id", function() {
var url = "/opgaver/kategori/" + $scope.Id + "/" + module.text;
$http.get(url).success(function(response) {
//RETURN TRUE OR FALSE TO .html view. PROBLEM HERE!!
});
})
}
});
ここ化するJsonResult:
[HttpGet]
public JsonResult CheckOpgave(int Id, string Text)
{
var db = Helpers.HelperToTables.DbValue;
var valuetext = Text.ToLower();
var check = db.LektionerOpgaves.FirstOrDefault(i => i.fk_LektionerId == Id && i.CorrectAnswer.Equals(valuetext));
if (check != null)
{
//succes
return Json("SUCCES");
}
else
{
//Error
return Json("ERROR");
}
}
ありがとう!助けを求める –