无法将ViewBag数据传递给AngularJS [英] Can't pass ViewBag data to AngularJS

查看:46
本文介绍了无法将ViewBag数据传递给AngularJS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个控制器:

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发出与第一个相同的东西?

The first instance of ViewBag.IsComplete (in the <p> tag) emits the correct value. The second emits null. Can anyone tell me what is going on here and how to fix it so the second @ViewBag.IsComplete emits the same as the first?

推荐答案

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

Use @Html.Raw(ViewBag.IsComplete) in your ng-init binding.

这篇关于无法将ViewBag数据传递给AngularJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆