AJBM Posted February 6, 2016 at 12:10 PM Report Share #593224 Posted February 6, 2016 at 12:10 PM Boas! Eu a fazer um pequeno exercício com angular e ASP.NET MVC, estou a tentar aplicar o principio deste video https://www.youtube.com/embed/f67PFtrldGQ?feature=oembed Eu tenho este controller. public class CustomerController : Controller { // GET: Customer public ActionResult Index() { return View(); } } Estas são as rotas que defini com angular. var customerApp = angular.module("CustomerApp", ["ngRoute"]); customerApp.config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) { $routeProvider. when('/Customer', { templateUrl: '/App/Customer/Views/CustomersList.html' }). when('/Customer/:id', { templateUrl: '/App/Customer/Views/CustomersDetails.html' }). otherwise({ redirectTo: '/Customer' }); $locationProvider.html5Mode(true); }]); View principal <!DOCTYPE html> <html ng-app="CustomerApp"> <head> <meta name="viewport" content="width=device-width" /> <title></title> <base href="/" /> </head> <body> <h1>Customer</h1> <div ng-view></div> <script src="~/Scripts/angular.js" type="text/javascript"></script> <script src="~/Scripts/angular-route.js" type="text/javascript"></script> <script src="~/App/Customer/CustomerApp.js" type="text/javascript"></script> </body> </html> Lista de Clientes Eu clico neste link e funciona. <h2>Lista</h2> <a href="/Customer/1">Customer 1</a> Mas quando eu estou na view /Customer/1 se fizer F5, como esta rota não está definida do lado do servidor dá erro. Existe alguma maneira contornar este problema, sem ter de adicionar um novo método ao CustomerController ? Link to comment Share on other sites More sharing options...
Solution AJBM Posted February 20, 2016 at 04:46 PM Author Solution Report Share #593712 Posted February 20, 2016 at 04:46 PM Modifiquei o ficheiro RouteConfig routes.MapRoute( name: "Default", url: "{controller}/{*catchall}", defaults: new { controller = "Main", action = "Index", id = String.Empty } ); Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now