AJBM 29 Report post Posted February 6, 2016 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 ? Share this post Link to post Share on other sites
AJBM 29 Report post Posted February 20, 2016 Modifiquei o ficheiro RouteConfig routes.MapRoute( name: "Default", url: "{controller}/{*catchall}", defaults: new { controller = "Main", action = "Index", id = String.Empty } ); Share this post Link to post Share on other sites