2016-08-23 58 views
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"); 
     } 
    } 

回答

1

你應該分配JSON返回給一個變量,然後使用你的NG-節目。

因此,例如:

$http.get(url).success(function(response) { 
      //RETURN TRUE OR FALSE TO .html view. PROBLEM HERE!! 
      $scope.jsonMessage = response; 

     }); 

然後在你的HTML,你會想這樣做:

<div ng-show="jsonMessage=='SUCCESS'"> 
      success 
     </div> 
     <div ng-show="jsonMessage=='ERROR'"> 
      Error 
     </div> 
+0

謝謝!求助 –

相關問題