nuget Instal-Paket softrouting -Versi 0.1.2
Kemudahan pengembangan
Hapus kode
Rute sederhana
Pengontrol aplikasi Standart Asp.net MVC di folder Pengontrol:
public class HomeController: Controller {
public HomeController() {
}
public ActionResult Index() {
return Content("index");
}
public ActionResult About() {
return Content("about");
}
public ActionResult Contacts() {
return Content("contacts");
}
}Perutean ke halaman indeks dengan perutean Asp.Net standar (indeks tindakan):
RouteTable.Routes.MapRoute(null, "", new {
controller: "Home",
action: "index"
});Perutean dengan SoftRouting:
using SoftRouting; //very important ¯_(ツ)_/¯
RouteTable.Routes.InController("Home").MapIndexPage("index"); //action name "index" as default pageMerutekan ke tindakan "tentang" && "kontak" dengan perutean Asp.Net
RouteTable.Routes.MapRoute(null, "about", new {
controller: "Home",
action: "about"
});
RouteTable.Routes.MapRoute(null, "contacts", new {
controller: "Home",
action: "contacts"
});Atau Anda dapat menggunakan perutean otomatis:
RouteTable.Routes.MapRoute(null, "{action}", new {
controller: "Home"
});Perutean dengan SoftRouting:
RouteTable.Routes.InController("Home")
.Map("about")
.Map("contacts");Atau Anda dapat menggunakan perutean otomatis
RouteTable.Routes.InController("Home").AutoMap(); //will map to ~/index, ~/about, ~/contactsPerutean otomatis dengan UrlPrefix
RouteTable.Routes.InController("Home").AutoMap("blogs"); //will map to ~/blogs/about, ~/blogs/contactsAnda juga dapat menggunakan ekspresi url di peta:
RouteTable.Routes.InController("Home")
.Map("about", "us/about")
.Map("contacts", "us/contacts");Dan Anda dapat menggunakan awalan untuk rute:
RouteTable.Routes.InController("Main").AutoMap("us");Anda dapat membuat rute di beberapa area
RouteTable.Routes.InArea("Main").WithController("Home")
.Map("about", "us/about")
.Map("contacts", "us/contacts");Anda dapat mengganti pengontrol dan area
RouteTable.Routes.InController("Home").AutoMap("us").SwitchArea("accounts").WithController("Login").AutoMap();
RouteTable.Routes.InController("Home").AutoMap("us").SwitchController("Login").AutoMap();Perutean di kelas AreaRegistration
using SoftRouting; ¯_(ツ)_/¯
public class MainAreaRegistration : AreaRegistration {
public override string AreaName => "Main";
public override void RegisterArea(AreaRegistrationContext context) {
context.WithController("Home")
.AutoMap();
}
}Anda dapat mengganti pengontrol
context.WithController("Home")
.AutoMap()
.SwitchController("Info")
.AutoMap("info");Dan Anda dapat mengganti Area
.AutoMap()
.SwithArea("Account")
.WithController("Login")
.AutoMap("accounts"); //~/accounts/login, ~/accounts/register etc...Terima kasih telah menginstal!