Is it possible to set page title with ViewBag in ASPX mode?
I have a master page called Default.master
. I want to set the title using ViewBag.Title
. On my controller I have:
public ActionResult Index()
{
ViewBag.Title = "Home";
return View();
}
My Home
view uses Default.master
as the master view page. On the master view page I am using:
<title><%= ViewBag.Title %></title>
But I get this error:
The call is ambiguous between t开发者_开发问答he following methods or properties: 'System.IO.TextWriter.Write(string, params object[])' and 'System.IO.TextWriter.Write(char[])'
How can I use it properly?
Try:
<title><%= (string) ViewBag.Title %></title>
From this blog post I saw a syntax that I've never seen before:
<%: %>
This prints an expression, so using:
<%: ViewBag.Title %>
I got the correct value.
your ViewBag.Title's value is null. maybe there are some exceptions happened. only in this case the ambiguous exception will thrown
精彩评论