加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

无法将ViewBag数据传递给AngularJS

发布时间:2020-12-17 07:09:23 所属栏目:安全 来源:网络整理
导读:我有一个控制器: public ActionResult Edit(int id) { ViewBag.IsComplete = false; return View(dbContext.Users.Where(user = user.Id == id))} 和相应的观点: @model User@{ ViewBag.Title = "Edit User"; Layout = "~/Views/Shared/_PopupLayout.cshtm
我有一个控制器:

public ActionResult Edit(int id) {
    ViewBag.IsComplete = false;
    return View(dbContext.Users.Where(user => user.Id == id))
}

和相应的观点:

@model User

@{
    ViewBag.Title = "Edit User";
    Layout = "~/Views/Shared/_PopupLayout.cshtml";
}

<p>@ViewBag.IsComplete</p>

<div ng-init="init(isComplete: @ViewBag.IsComplete)" />

ViewBag.IsComplete的第一个实例(在< p>标记中)会发出正确的值.第二个发出null.任何人都可以告诉我这里发生了什么,以及如何解决它,以便第二个@ ViewBag.IsComplete发出与第一个相同的?

解决方法

在ng-init绑定中使用@ Html.Raw(ViewBag.IsComplete).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读