使用MVC-3,剃刀:MVC-3和动态 - @ Html.Label(View.X)不渲染
- myController的 -
public ActionResult Index(String message) // where message = "hello"
{
ViewModel.Test1 = "This is a test";
ViewModel.Test2 = "This is another test. " + message;
}
- Index.cshtml -
@Html.Label((string)View.Test1)
<br />
@Html.Label((string)View.Test2)
为什么它只渲染出以下内容?
<label for="This is a test">This is a test</label>
<br />
在过去的几天里,我一直让我疯狂,似乎没有任何意义。必须有一个原因。
我可以调试这一点,并通过这个视图。在视图中,我注意到这行被处理,View.Test2的值是“This is another test。hello”。
我有我在做以下事情的情况下,它工作正常。
(前)
ViewModel.Something = this.readDataService.GetSomething();
有什么区别?
感谢,
罗布
漂流,谢谢你的回复。感谢提示让我的应用程序转移到最新的MVC。你是对的,我应该在所有这些观点中使用一个模型作为经验法则。我会走这条路,并保存ViewBag的头痛。(顺便说一下,我在迁移到较新的MVC之后测试了我的应用程序,但它仍然存在同样的问题。模型的时间!)再次感谢您的响应! – Rob 2011-03-04 05:16:51
@Rob,很高兴我能帮忙:) – 2011-03-04 05:23:33