我似乎无法通过 ViewBag 或 ViewData 将任何数据传递给视图。它只是不断地以空值返回。
查看结果代码:
public ViewResult EditProduct(Guid id)
{
var product = _repository.Products.FirstOrDefault(x => x.ID == id);
ViewData["Categories"] = _repository.Categories;
ViewData["CategoryList"] = _repository.Categories.Select(x => new SelectListItem { Text = x.Name, Value = x.ID.ToString(), Selected = product.ID == x.ID });
ViewBag.Test = "Hello";
return View(product);
}
这是剃刀代码:
@model NightingalecrossMVC.Domain.Entities.Product
@{
var test = ViewData.Eval("CategoryList");
var test2 = ViewBag.Test;
ViewBag.Title = "Edit Treatment";
AjaxOptions ajaxOpts = new AjaxOptions
{
UpdateTargetId = "saveData",
HttpMethod = "Post",
LoadingElementId = "loader"
};
}
为什么会这样?它在任何其他视图上都可以正常工作?!