Question

Just got started with asp.net MVC. Created my first controller

public ActionResult Index()
    {
        ViewData["CurrentTime"] = DateTime.Now.ToString();
        return View();
    }

And tried to set show the CurrentTime in the view like

<%: ViewData["CurrentTime"] %>

But its giving the below error:

Compiler Error Message: CS1525: Invalid expression term ':'

Update: i'm using framework 3.5

Était-ce utile?

La solution

The syntax is wrong. Try

<%= ViewData["CurrentTime"] %>

Instead of

<%: ViewData["CurrentTime"] %>

Autres conseils

Try with

    <%: (string)ViewData["CurrentTime"] %>

Stil, i think that you should try to use Razor. Its much frindly and it has a lot more features than aspx.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top