标签:remove nuget rar mode mvc razor 控制 put 请求
1. 关键词--路由
配置整个Web系统的路径结构,一般在 Global.asax.cs 中执行 RouteConfig.RegisterRoutes。
public class RouteConfig { public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); } }
2. 关键词--Controller
namespace WebApplication.Controllers { public class HomeController : Controller { public ActionResult Index() { ViewBag.Greeting = DateTime.Now.Hour < 12 ? "Good morning" : "Good afternoon"; return View(); } } }
3. 关键词--视图文件
@{ ViewBag.Title = "Home Page"; } <div class="jumbotron"> <h1>ASP.NET</h1> <p class="lead">ASP.NET is a free web framework for building great Web sites and Web applications using HTML, CSS and JavaScript.</p> <p><a href="http://asp.net" class="btn btn-primary btn-large">Learn more »</a></p> </div> <div class="row"> <div> <p>@ViewBag.Greeting, guest!</p> @Html.ActionLink("RSVP Now", "RsvpForm"); </div> <div class="col-md-4"> <h2>Getting started</h2> <p> ASP.NET MVC gives you a powerful, patterns-based way to build dynamic websites that enables a clean separation of concerns and gives you full control over markup for enjoyable, agile development. </p> <p><a class="btn btn-default" href="http://go.microsoft.com/fwlink/?LinkId=301865">Learn more »</a></p> </div> <div class="col-md-4"> <h2>Get more libraries</h2> <p>NuGet is a free Visual Studio extension that makes it easy to add, remove, and update libraries and tools in Visual Studio projects.</p> <p><a class="btn btn-default" href="http://go.microsoft.com/fwlink/?LinkId=301866">Learn more »</a></p> </div> <div class="col-md-4"> <h2>Web Hosting</h2> <p>You can easily find a web hosting company that offers the right mix of features and price for your applications.</p> <p><a class="btn btn-default" href="http://go.microsoft.com/fwlink/?LinkId=301867">Learn more »</a></p> </div> </div>
4. HttpGet、HttpPost 属性
public class HomeController : Controller { public ActionResult Index() { ViewBag.Greeting = DateTime.Now.Hour < 12 ? "Good morning" : "Good afternoon"; return View(); } [HttpGet] public ActionResult RsvpForm() { return View(); } [HttpPost] public ActionResult RsvpForm(GuestResponse response) { return View("Thanks", response); } public ActionResult About() { ViewBag.Message = "Your application description page."; return View(); } public ActionResult Contact() { ViewBag.Message = "Your contact page."; return View(); } }
5. Html 辅助器方法与模型绑定
@model WebApplication2.Models.GuestResponse @{ ViewBag.Title = "RsvpForm"; } <!DOCTYPE html> <html> <head> <title>RsvpForm</title> </head> <body> @using (Html.BeginForm()) { <p>Your name: @Html.TextBoxFor(x => x.Name)</p> <p>Your email: @Html.TextBoxFor(x => x.Email)</p> <p>Your phone: @Html.TextBoxFor(x => x.Phone)</p> <p> Will you attend? @Html.DropDownListFor(x => x.WillAttend, new []{ new SelectListItem(){ Text = "Yes, I‘ll be there", Value = bool.TrueString }, new SelectListItem(){ Text = "No, I can‘t come", Value = bool.FalseString } }, "Choose an option") </p> <input type="submit" value="Submit RSVP" /> } </body> </html>
6. 模型绑定后值的使用
@model WebApplication2.Models.GuestResponse @{ ViewBag.Title = "Thanks"; } <!DOCTYPE html> <html> <head> <title>RsvpForm</title> </head> <body> <div> <h1>Thank you, @Model.Name</h1> @if (Model.WillAttend == true) { @:It is great that you‘re coming, The drinks are already in the fridge! } else { @:Sorry to hear that you can‘t make it, but thanks for letting us know. } </div> </body> </html>
标签:remove nuget rar mode mvc razor 控制 put 请求
原文地址:http://www.cnblogs.com/Daniel-Liang/p/6501958.html