public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseMvc(routes =>
{
routes.MapRoute(
name: "goto_one",
template: "one",
defaults: new { controller = "Home", action = "PageOne" });
routes.MapRoute(
name: "goto_two",
template: "two/{id?}",
defaults: new { controller = "Home", action = "PageTwo" });
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
public class MobileController : Controller
{
public IActionResult Index()
{
var url = Url.Action("Index"); // /mobile
return Content($"Mobile/Index (Url: {url})");
}
public IActionResult PageOne()
{
var url = Url.Action("PageOne"); // /mobile/PageOne
return Content($"Mobile/One (Url: {url})");
}
[HttpGet]
public IActionResult PageTwo()
{
var url = Url.Action("PageTwo"); // /mobile/PageTwo OR /mobile/PageTwo/1?
return Content($"(GET) Mobile/Two (Url: {url})");
}
[HttpPost]
public IActionResult PageTwo(int id)
{
var url = Url.Action("PageTwo"); // /mobile/PageTwo/1
return Content($"(POST) Mobile/Two: {id} (Url: {url})");
}
public IActionResult PageThree()
{
var url = Url.RouteUrl("goto_two", new { id = 5 }); // /two/5
return Content($"Mobile/Three (Url: {url})");
}
public IActionResult PageFour()
{
var url = Url.RouteUrl("goto_two", new { q = 5 }); // /two?q=5
return Content($"Mobile/Four (Url: {url})");
}
public IActionResult PageFive()
{
return RedirectToAction("PageSix");
}
public IActionResult PageSix()
{
return Content("Mobile/Six (Mobile/Five will also come here)");
}
}
public IActionResult PageTwo(int id)
{
var url = Url.Action("PageTwo"); // /mobile/PageTwo/1
return Content($"(POST) Mobile/Two: {id} (Url: {url})");
}
public IActionResult PageThree()
{
var url = Url.RouteUrl("goto_two", new { id = 5 }); // /two/5
return Content($"Mobile/Three (Url: {url})");
}
public IActionResult PageFour()
{
var url = Url.RouteUrl("goto_two", new { id=5, key1 = "value1" }); // /two/5?key1=value1
return Content($"Mobile/Four (Url: {url})");
}
public IActionResult PageFive()
{
return RedirectToAction("PageSix");
}
public IActionResult PageSix()
{
return Content("Mobile/Six (Mobile/Five will also come here)");
}
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<IActionContextAccessor, ActionContextAccessor>();
services.AddScoped<IUrlHelper>(factory =>
{
var actionContext = factory.GetService<IActionContextAccessor>().ActionContext;
return new UrlHelper(actionContext);
});
services.AddMvc();
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有