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

Was it helpful?

Solution

The syntax is wrong. Try

<%= ViewData["CurrentTime"] %>

Instead of

<%: ViewData["CurrentTime"] %>

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top