我使用的是asp.net mvc4。覆蓋方法,如果類是DLL
我正在使用DLL,所以我必須重寫類來擴展新的方法。
我有這樣一個觀點:從這個類
@model SalesAgentLoginInfoModel
<div class="top-dropdown login">
<div class="opener collapsed">
<span class="login-title">@Sana.SimpleText("Account")</span>
</div>
<div class="summary">
<div class="welcome border-horizontal">
@Sana.SimpleText("Login_Welcome")
<span class="user-name">@Model.Name</span>
</div>
<a href="@Url.Sana.MyAccount()" class="hyp">@Sana.SimpleText("Login_MyAccount")</a>
<a href="@Url.Sana.RepresentCustomer()" class="hyp">@Sana.SimpleText("ButtonText_RepresentCustomer")</a>
<a href="@Url.Sana.RepresentCustomer()" class="hyp">@Sana.SimpleText("ButtonText_baliecode")</a>
dlkfnslkdf
<div class="logout border-horizontal">
<a id="logoutLink" href="@Url.Sana.Logout()" class="arrow-blue">@Sana.SimpleText("Logout_LinkText")</a>
</div>
</div>
</div>
而且RepresentCustomer()是:
// Summary:
// The web shop URLs constructor.
public class UrlsBuilder
{
public virtual string RepresentCustomer(string returnUrl = null);
//
// Summary:
// Gets the URL to the reset password page.
//
// Returns:
// The reset password page URL.
//
// Summary:
// Initializes a new instance of the Sana.Commerce.Web.Routing.UrlsBuilder class.
//
// Parameters:
// routes:
// The route collection.
public UrlsBuilder(RouteCollection routes);
//
// Summary:
// Gets the instance of Sana.Commerce.Web.Routing.UrlsBuilder.
public static UrlsBuilder Current { get; }
//
// Summary:
// The routes used to construct URLs.
public RouteCollection Routes { get; protected set; }
//
// Summary:
// Gets the URL to the add review page.
//
// Parameters:
// productId:
// The product ID.
//
// returnUrl:
// The return URL.
//
// navigationNodeId:
// The navigation node ID.
//
// Returns:
// The add review page URL.
public virtual string AddReview(string productId, string returnUrl = null, string navigationNodeId = null);
}
因此,我已擴展的類UrlsBuilder像這樣的新方法:
public class V_ExtendendURlsBuilder : UrlsBuilder
{
public V_ExtendendURlsBuilder(RouteCollection routes) : base(routes)
{
}
public virtual string BaliecodeVerkoper(string url)
{
return url;
}
}
但是,如果我試圖在視圖中調用像這樣的新方法:
<a href="@Url.Sana...." class="hyp">@Sana.SimpleText("ButtonText_baliecode")
我沒有看到新的方法BaliecodeVerkoper。
還有一件事。該public UrlsBuilder Sana { get; }
是這個類中:
public class FrontendUrlHelper : SanaUrlHelper
{
//
// Summary:
// The facet values query string separator.
public const string FacetValuesSeparator = "\n";
//
// Summary:
// Initializes a new instance of the Sana.Commerce.Web.Frontend.FrontendUrlHelper
// class.
//
// Parameters:
// requestContext:
// The request context.
public FrontendUrlHelper(RequestContext requestContext);
//
// Summary:
// Gets the Sana URLs builder.
public UrlsBuilder Sana { get; }
//
// Summary:
// Creates a new instance of the frontend URL helper initialized with the specified
// requestContext. It can be a standard helper class or a customized version if
// it is registered through the Sana.ObjectManager.
//
// Parameters:
// requestContext:
// The request context.
//
// Returns:
// Returns a new instance of the frontend URL helper.
public static FrontendUrlHelper Create(RequestContext requestContext);
//
// Summary:
// Reads the selected facets from the query string of the current request.
//
// Parameters:
// facets:
// The collection of all available facets.
public void ReadSelectedFacets(FieldFilterCollection facets);
//
// Summary:
// Sets the selected facets in the query string of the specified url.
//
// Parameters:
// url:
// The base URL.
//
// facets:
// The facets.
//
// Returns:
// Returns the url with the selected facets in its query string.
public virtual string SetSelectedFacets(string url, FieldFilterCollection facets);
//
// Summary:
// Reads the selected facets from the specified query string dictionary.
//
// Parameters:
// queryString:
// The query string.
//
// facets:
// The facets.
protected virtual void ReadSelectedFacets(NameValueCollection queryString, FieldFilterCollection facets);
//
// Summary:
// Sets the selected facets into the queryString.
//
// Parameters:
// queryString:
// The query string dictionary.
//
// facets:
// The facets.
protected virtual void SetSelectedFacets(NameValueCollection queryString, FieldFilterCollection facets);
}
所以我的問題:如何擴展新方法UrlsBuilder?
謝謝
一個其他的嘗試是嘗試這樣的:
public class V_ExtendendURlsBuilder : UrlsBuilder
{
public V_ExtendendURlsBuilder(RouteCollection routes) : base(routes)
{
}
public virtual string BaliecodeVerkoper(string url)
{
return url;
}
}
但我仍然看不到那麼新方法:
public class ExtendFrontEndUrlHelper : FrontendUrlHelper
{
public UrlsBuilder builder;
public ExtendFrontEndUrlHelper(RequestContext requestContext) : base(requestContext)
{
}
public UrlsBuilder BalieCode()
{
return builder;
}
}
我只是想用新的方法Baliecode擴展UrlsBuilder類。這樣我就可以在視圖中使用該方法。但UrlsBuilder是一個DLL。所以我必須用一種新方法擴展這個類。
我希望我現在清楚。
看到我的圖片。所以我還沒有看到新的方法Baliecode
謝謝
,但如何在視圖中使用它呢?
<a href="@Url." class="hyp">@Sana.SimpleText("ButtonText_baliecode")</a>
@Url ..然後?我沒有看到擴展...
如果我去:現在
public abstract class SanaWebViewPage : SanaWebViewPageBase
{
protected SanaWebViewPage();
//
// Summary:
// Gets the Sana view helper.
public SanaViewHelper Sana { get; set; }
//
// Summary:
// Gets or sets the Sana.Commerce.Web.Frontend.FrontendUrlHelper object that is
// used to manage the URLs.
//
// Returns:
// The current Sana.Commerce.Web.Frontend.FrontendUrlHelper.
public FrontendUrlHelper Url { get; set; }
//
// Summary:
// Gets the page info.
protected virtual WebPageInfo PageInfo { get; }
//
// Summary:
// Initializes the helpers.
public override void InitHelpers();
}
奧凱,我有它,就像這樣::
<a href="@Url.Sana" class="hyp">@Sana.SimpleText("ButtonText_baliecode")</a>
,然後F12上@Url
我看到這個類
public class extendedSanaWebviewPage : SanaWebViewPage
{
public ExtendFrontEndUrlHelper extendedFrontEndUrlHelper { get; set; }
public override void Execute()
{
throw new NotImplementedException();
}
}
但是我不要在視圖中沒有看到:@extendedFrontEndUrlHelper
謝謝
好像你想一個解決辦法,使UrlsBuilder行爲,如果它有BaliecodeVerkoper,但由於UrlsBuilder被鎖定在一個DLL中,所以你不能直接修改它。是對的嗎? – Malachi
是的,但是你可以擴展這個類。就像我的例子。然後你可以添加一個新的方法。但是,如果我這樣做。我仍然沒有看到視圖中的新方法。所以是的。我嘗試在UrlsBuilder類中添加一個新方法。不是直接的,因爲它是一個DLL。所以我嘗試從UrlsBuilder類中擴展一個新類 –
您是否可以將「public UrlsBuilder Sana {get;}」更改爲「public V_ExtendedURLsBuilder Sana {get;}」? – Malachi