Issue
I have written web application on .net 2017 c#, I had to change my URL to simpler in order to get rid of ? or = from URL and also I am using Google Map on my web site. When I click to records which will be redirected and changed to other link, I got this error.
Original url is: mydomain.com/Doctor?id=XX
I converted it to: mydomain.com/Doctor/XX
I did it by defining new MapRoute on RegisterRoutes as: RouteCofig.cs:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Blog", // Route name
"Doctor/{id}", // URL with parameters
new { controller = "Home", action = "PersianDR", id = UrlParameter.Optional } // Parameter defaults
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
I also used angularjs: Angular Module:
var app = angular.module('MyApp', ['ngRoute', 'uiGmapgoogle-maps', 'nemLogging', 'ngSanitize']);
app.config(['$routeProvider', '$locationProvider', function ($routeprovider, $locationProvider) {
$routeprovider.
when('/Home/PersianDR/:id', {
templateurl: '/Views/Home/PersianDR.cshtml',
controller: 'AngularCtrl_ShowDr'
})
.
when('Doctor/:id', {
redirectto: '/Home/PersianDR/:id'
})
.
otherwise({
redirectto: '/'
})
;
//$locationProvider.html5Mode(true);
$locationProvider.html5Mode({
enabled: true,
rewriteLinks: false
});
}]);
Angular Controller:
app.controller("AngularCtrl_ShowDr", function ($scope, $location, angularService_ShowDr, $route, $routeParams, $http, $sce) {
var docId = $("#myId").val();
$location.path();
$location.url('Doctor/' + docId).replace();
GetDoctorByID();
GetGeoCoordinates();
maps();
});
This problem as been started since I changed URL.
Solution
I finally found an interesting answer. There is a conflict when I wanted to redirect and make my url simple while I am using google map apis, this is because gmap needs absolute path or url while I wanted to change my url simple and elegant.
What I did to remove holding on waiting to load csi.gstatic.com, was to use partial view.
I totally brought my ui-gmap-google-map inside partial view and called it from original one.
In original page.cshtml:
@Html.Partial("_MapDoctor")
In partial view , _MapDoctor.cshtml:
<div ng-controller="AngularCtrl_MapDr">
<input type="hidden" id="myId2" value="@ViewBag.id" />
<ui-gmap-google-map center='mapsdrsec.center' zoom='mapsdrsec.zoom' options='mapsdrsec.options'>
<ui-gmap-layer type="TrafficLayer" show="mapsdrsec.showTraficLayer"></ui-gmap-layer>
<ui-gmap-markers models="markers" idkey="markers.id" coords="'coords'">
</ui-gmap-markers>
</ui-gmap-google-map>
</div>
I wrote specified controller and services in angularjs for partial view. I deleted filling $scope.map from original and wrote (center, zoom, options, $scope.markers ) in partial view controller.
Answered By - Mahsa Hassankashi
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.