Bru*_*oLM 5 asp.net-mvc asp.net-mvc-3
我有一个名为的母版页Default.master.我想用标题设置ViewBag.Title.在我的控制器上我有:
public ActionResult Index()
{
ViewBag.Title = "Home";
return View();
}
Run Code Online (Sandbox Code Playgroud)
我的Home视图用Default.master作主视图页面.在我正在使用的主视图页面上:
<title><%= ViewBag.Title %></title>
Run Code Online (Sandbox Code Playgroud)
但我得到这个错误:
The call is ambiguous between the following methods or properties: 'System.IO.TextWriter.Write(string, params object[])' and 'System.IO.TextWriter.Write(char[])'
Run Code Online (Sandbox Code Playgroud)
我怎样才能正确使用它?
在这篇博文中,我看到了一种我以前从未见过的语法:
<%: %>
Run Code Online (Sandbox Code Playgroud)
这会打印一个表达式,所以使用:
<%: ViewBag.Title %>
Run Code Online (Sandbox Code Playgroud)
我得到了正确的价值.
| 归档时间: |
|
| 查看次数: |
8384 次 |
| 最近记录: |