我有一个控制器:
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).