POST后刷新页面

时间:2015-04-12 13:08:48

标签: c# angularjs post model-view-controller refresh

我已经创建了一个解决方案,我将一个字符串数组发布到我的控制器。 设置工作正常,但我必须手动刷新页面才能看到我的方法的结果。 我发布后如何让解决方案刷新页面?

我的观点(tree.html):

<form>
 <textarea class="form-control auto-input-field" rows="10" cols="80" id="autoGenerateInputField" ng-model="fighterList" ng-list="/\n/" />
 <input class="btn btn-primary" type="submit" ng-click="GenerateTournamentTree(data)" value="Generer kamptræ" />
</form>

我的js(有角度):

$scope.GenerateTournamentTree = function(matches){
    var stringOfFighters = new Array();
    var categoryId = $scope.CategoryId;
    stringOfFighters = $scope.fighterList;
    var postData = { fighters: stringOfFighters };

    if (stringOfFighters != null) {
        $.ajax({
            type: "POST",
            url: "/Api/Match/GenerateTournamentTree",
            contentType: 'application/json; charset=utf-8',
            data: JSON.stringify(stringOfFighters),
            success: function (data) {
                alert(data.Result);
            },
            dataType: "json",
            traditional: true
        });
    } else {
        $modal.open({
            templateUrl: 'generateTreeMessage.html',
            scope: $scope,
            controller: function ($scope) {
                $scope.ok = function () {
                    $scope.$dismiss();
                }
                $scope.cancel = function () {
                    $scope.$dismiss();
                }
            }
        })
    }
}

我的控制器:

[Route("api/Match/GenerateTournamentTree")]
public IHttpActionResult GenerateTournamentTree(List<String> fighters)
{
    fighters.Shuffle();
    var nodeTree = InsertNode(new TreeNode(), fighters);
    var matches = new List<MatchRecord>();
    GenerateMatch(matches, nodeTree);
    foreach(var match in matches)
    {
        match.CategoryId = new Guid("425d750e-56bd-412c-8a48-38c2fbe5b24c");
        match.EventId = 18;
    }
    db.Matches.AddRange(matches);
    try
    {
        db.SaveChanges();
    }
    catch (DbUpdateException)
    {               
        throw;              
    }

    //return CreatedAtRoute("DefaultApi", new { id = "18" }, fighters);
    //I tried this but with no succes.

    return Json(new { Result = fighters });
    //this is only created to return something.
}

0 个答案:

没有答案