I'm following the tutorial at asp.net mvc3 at http://www.asp.net/mvc/tutorials/getting-started-with-mvc3-part3-cs
@{
ViewBag.Title = "Welcome";
}
<h2>Welcome</h2>
<ul>
@for (int i=0; i < ViewBag.NumTimes; i++) {
<li>@ViewBag.Message</li>
}
</ul>
the hellowWorldcontroller
using System.Web;
using System.Web.Mvc;
namespace MvcApplication1.Controllers
{
public class HelloWorldController : Controller
{
// GET: /HelloWorld/
/*public void Index()
{
//return "This is my <b>default</b> action...";
return View;
}*/
public ActionResult Index()
{
//ViewBag.Message = "Welcome to ASP.NET MVC!";
return View();
}
//
// GET: /HelloWorld/Welcome/
public ActionResult Welcome(string name, int numTimes = 1)
{
return View();
//return HttpUtility.HtmlEncode("Hello " + name + ", NumTimes is: " + numTimes);
}
}
}
But it seems that in cshtml, it can't run the asp.net code, only display the static content, why?
And the cshtml also don't apply to the MainContent master page, there is only plain text without any background and button when I run the application, where's the problems?
ViewBag.NumTimes = numTimes;in Welcome action.<title>@ViewBag.Title</title>in html head section. I guess that it must be located in some layout page.