1.Controller
1) Add:
Right in the Controller directory to add, there are many models to choose from Controller, choose an empty, named after the New. After New Views
Directory synchronization will generate the corresponding view file directory names
They are inherited from the Controller class
The method in the controller ActionResultl default return type, can modify
Run modified and added to the file name in the directory automatically generated Views in the domain name, you can access to the route
The route through / Hello access
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; namespace HelloMVC.Controllers { public class HelloController : Controller { // GET: Hello public string Index() { return "Hello MVC"; } } }
Can also create their own methods (routing): The route through / Hello / Yes access
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; namespace HelloMVC.Controllers { public class HelloController : Controller { // GET: Hello public string Index() { return "Hello MVC"; } public string Yes() { return "Yse MVC, this is Yes."; } } }
If you want to pass url parameter, the parameter is added to the above-described methods
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; namespace HelloMVC.Controllers { public class HelloController : Controller { // GET: Hello public string Index() { return "Hello MVC"; } public string Yes(string name) { return "Yse MVC, this is Yes." + name; } } }
But doing so less secure
When a user typically receives mass participation we first conduct a code:
May also be transmitted adds a default parameter
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; namespace HelloMVC.Controllers { public class HelloController : Controller { // GET: Hello public string Index() { return "Hello MVC"; } // 参数缺省值 public string Yes(string name = "Linda") { return "Yse MVC, this is Yes." + HttpUtility.HtmlEncode(name); //或 return "Yse MVC, this is Yes." + Server.HtmlEncode(name); } } }
Tip: F5 key Debug mode, execution breakpoint
ctrl + F5 Debug mode without execution breakpoint
We will use the test to build a suggestion IIS server
You can view some configuration files Global.asax routes
RegisterRoutes method
2) debugging techniques: