Some ways of MVC route and Angular Router single page

Source: Internet
Author: User

Look directly at the code and comments.

ASP. NET MVC Router

 Public classrouteconfig{ Public Static voidregisterroutes (routecollection routes) {routes. Ignoreroute ("{Resource}.axd/{*pathinfo}"); Routes. Ignoreroute ("Favicon.ico"); Routes.  Mapmvcattributeroutes (); //be sure to routes. MapRoute before registration//single-page processingroutes. MapRoute (Name:"Personalprofile", URL:"Personal-profile/{*pathinfo}",//This allows you to connect all under Personal-profile paths to the same controller.DefaultsNew{controller ="Personalprofile", action ="Index", PathInfo ="PathInfo" }        ); //The general treatmentroutes. MapRoute (Name:"Default", URL:"{Controller}/{action}/{id}", defaults:New{controller ="Home", action ="Index", id =urlparameter.optional}); }}

ASP. NET Controller

[Routeprefix ("personal-profile")]publicclass  personalprofilecontroller:controller{            //[route ("")]    public ActionResult Index (string  pathInfo)    {        //PathInfo We can also handle it separately        return  View ();}    }

One thing to note here is that if you use Attributeroute, Routemap will not work.

Cshtml Angular

@{Layout = null;}<!DOCTYPE HTML><HTMLNg-app= "App"Ng-controller= "Ctrl"><Head>        <Basehref= "http://localhost:58404/personal-profile/" />    <Metaname= "Viewport"content= "Width=device-width" />    <title>Index</title></Head><Body>Personal Profile<Scriptsrc= "~/js/jquery.js"></Script>    <Scriptsrc= "~/js/angular.js"></Script>    <Script>                varapp=Angular.module ("app", []); App. Config (["$locationProvider", function($locationProvider) {//Note:            //because angular will compare the URL of the browser when doing $location and <base>            //and it's case-sensitive, so it's easy to error.            //you won't have this problem after reset.            //the procedure is to take the URL of the browser replace into base href            varWholeurl=Location.href; varBaseelem=document.getElementsByTagName ("Base")[0]; varBASEURL=Baseelem.href; varNewbaseurl=wholeurl.substring (0, baseurl.length); Baseelem.href=Newbaseurl; $locationProvider. Html5mode ({enabled:true, Requirebase:true            });        }]); App.controller ("Ctrl", ["$location", function($location) {Console.log ("Start");    }]); </Script></Body></HTML>

Notice the conflict between angular and base

Some ways of MVC route and Angular Router single page

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.