문제

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

도움이 되었습니까?

해결책

The syntax is wrong. Try

<%= ViewData["CurrentTime"] %>

Instead of

<%: ViewData["CurrentTime"] %>

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top