0

I am using VS2015, C# and angular 1.4.5.

Those are my settings:

enter image description here

Link in my button:

 <button ng-click="PartialPageLink = 'FirstTestProject/Album/Album';">                  
    Album
</button>

And ng-include directive:

<div id="divRight" ng-include="PartialPageLink"></div>   

Everything is working fine. Divsion 'divRight' gets populated with PartialPageView. Untill I press one of the buttons which are redirecting to new page, like this one:

<button onclick="location.href='@Url.Action("NewUserRegistration","RegisterNewUser")'">          
    New user
</button>

I've got redirected to new page. From that page I return to my base page which is http://localhost/FirstTestProject.

If I press button for partial page updating, my link becomes:

/FirstTestProject/FirstTestProject/Album/Album

and I receive 404 - not found error. Any idea why is 'FirstTestProject' prepended to PartialPageLink only if I open new page between calls?

FrenkyB
  • 6,625
  • 14
  • 67
  • 114

1 Answers1

0

I've found a solution to the problem here

I still don't understand why this is happening and why relative link is OK at the beginning and after opening another page it becomes corrupt. My code is slightly modified from original, I've just put single quotes around url. Now I always use absolute url and this solves the problem.

using System;
using System.Web;
using System.Web.Mvc;

namespace FirstTestProject.Helpers
{
    public static class UrlExtensions
    {
        public static string Content(this UrlHelper urlHelper, string contentPath, bool toAbsolute = false)
        {
            var path = urlHelper.Content(contentPath);
            var url = new Uri(HttpContext.Current.Request.Url, path);
            string newUrl = toAbsolute ? url.AbsoluteUri : path;
            return string.Format("{0}{1}{2}", "'", newUrl, "'");
        }
    }
}
Community
  • 1
  • 1
FrenkyB
  • 6,625
  • 14
  • 67
  • 114