B Z*_*B Z 3 asp.net-mvc razor asp.net-mvc-3
我正在使用MVC 3 w/Razor并使用新的动态ViewBag属性.我想将ViewBag属性与EditorFor/LabelFor Html助手一起使用,但无法弄清楚语法.
View确实有@model设置,但我尝试使用的对象不是该模型的一部分.我知道我可以创建一个ViewModel,但这不是我想要的.
有人可以帮忙吗?
控制器:
var myModel= _repo.GetModel(id);
var newComment = new Comment();
ViewBag.NewComment = newComment;
return View(myModel);
Run Code Online (Sandbox Code Playgroud)
视图:
@model Models.MyModel
@(Html.EditorFor(ViewBag.NewComment.Comment))
Run Code Online (Sandbox Code Playgroud)
我没有尝试过,但我认为这应该有效.
@(EditorFor(m => ViewBag.NewComment)
Run Code Online (Sandbox Code Playgroud)
可以使用Linq-to-SQL语法,但在右侧使用完全不同的对象.