I have the following part of a view model that fills in a partial view:
public string DownloadLink { get { UrlHelper url = new UrlHelper(HttpContext.Current.Request.RequestContext); switch (this.Type) { case (int)DocumentTypes.WasteNote: { return url.Action("PaperWork", "Jobs", new { JobId = this.DOCJobId }, HttpContext.Current.Request.IsSecureConnection ? "https" : "http" ); } case (int)DocumentTypes.Contract: case (int)DocumentTypes.DestructionCert: case (int)DocumentTypes.Quote: default: { return url.Action("Download", "Documents", new { DocId = this.DocumentLinkId }, HttpContext.Current.Request.IsSecureConnection ? "https" : "http"); } } } }
Called in a view this way:
@model IEnumerable<Document> @using CustomerDashboard.ViewModels; @using CustomerDashboard.Utilities; @{ Layout = null; } @foreach (Document doc in Model) { <li> <a href="@doc.DownloadLink" class="documentDownload"> <div class="col-sm-12 col-md-5 li-row li-row-icon"> <div class="pull-left"> <img height="40" src="/Content/img/file-icons/@doc.Icon" /> </div> ... </a> </li> }
So far this is being visualized directly in a different view. The generated link is fine, however I serialize the partial and return as JSON:
public string RenderRazorViewToString(string viewName, object model) {
Then it returns as Json from the controller:
return Json(new { totalCount = (int)Session["DocumentTotalCount"], markup = RenderRazorViewToString("_DocumentListAjax", docs) },JsonRequestBehavior.AllowGet);
To be clear, the problem is JSON serialization - this is nasty, but removes the www prefix:
return Json(new { totalCount = (int)Session["DocumentTotalCount"], markup = RenderRazorViewToString("_DocumentListAjax", docs).Replace("www.","") },JsonRequestBehavior.AllowGet);
At the same time, from what seems to be outside the local network (which sounds strange), all URLs have www preended - i.e. https://example.com becomes https://www.example.com . I am trying to find out why this is happening and how to fix it.