In the view, we will use a lot of a and img labels. They can only accept relative paths. But in the MVC Framework, views are all placed in different folders. How can we better specify their paths?
The general method is to roll back to the upper-level directory through the... method. This can be solved in general views. However, if the Index Action is used, it will be a little troublesome, because the index can be omitted by default. Let's think about it. Do we need to write a... to roll back the level or write two... to roll back the level? This is a very troublesome task.
My practice is to use a variable to save the virtual path of the current website, so that there will be no problem. The following is an example.
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<Web.Models.PhotoListItem>>" %><% var root = Request.Url.GetLeftPart(UriPartial.Authority);%><% foreach (var item in Model) {%><a href='<%= root+"/Photo/Large/"+ Html.Encode(item.Path) %>' title="<%= Html.Encode(item.Title) %>"> ' path='<%= root+"/Photo/Normal/"+ Html.Encode(item.Path) %>' alt="" /></a><% } %>