我使用的是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