【问题标题】:View is not rendering视图未呈现
【发布时间】:2017-09-14 07:20:22
【问题描述】:

下面是我的角码

MDIApp.controller("loginCtrl", function ($scope, $http,$location,$sce) { 
        $scope.toTrustedHTML = function (html) {
            return $sce.trustAsHtml(html);
        }

        $scope.getLogin = function (proCode) {
            alert("Code " + proCode);
            $http({
                method: 'GET',
                url: '/Home/getProviderLogin?id=' + proCode,
            }).
            success(function (data) {
                debugger;
                $scope.ProviderLogin = data;
                $scope.ProviderLoginPop = true;
                //$location.path = '~/WelcomePage.cshtml';
                $http.post("/Home/WelcomePage", { postId: id });
            });

        }
    });

下面是我的控制器代码

public ActionResult getProviderLogin(string id)
        {
            var providercode = objHomeRepo.getLogin(id);
            //return View("WelcomePage");
            return RedirectToAction("WelcomePage", "Home");

        }

我正在尝试调用welcomepage 视图,但它没有呈现......

【问题讨论】:

  • $http 是异步请求所以你认为RedirectToAction 会工作吗?
  • 我是角度新手,请建议
  • 我尝试使用 return view("WelcomePage");同样的问题

标签: angularjs model-view-controller angularjs-directive angular-ui-router angularjs-scope


【解决方案1】:

重定向在 ajax 帖子中不起作用。您可以在控制器中返回目标 url 并在 javascript 代码中手动重定向它。

在您的控制器中,返回您的网址

return Json(Url.Action("WelcomePage", "Home"));

在您的 javascript 代码中使用

$location.path('url')

window.location.href = url;

【讨论】:

    猜你喜欢
    • 2016-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-27
    • 2013-06-17
    相关资源
    最近更新 更多