简体   繁体   English

如何使用N2CMS获取另一个内容项的url?

[英]How to get the url of another content item with N2CMS?

I use N2CMS version 2.9.6.8 and let's say I opened the account/login page, then I want to click on the subscribe link below the login form. 我使用的是N2CMS版本2.9.6.8,假设我打开了“帐户/登录”页面,然后单击登录表单下方的订阅链接。

So, how to get the url of the subscribe page to build the ahref tag correctly? 因此,如何获取订阅页面的网址以正确构建ahref标签?

The website has many languages and if I want to build the href tag this way: 该网站有多种语言,如果我想以这种方式构建href标签:

<a href="@Url.Action("Index", "Subscription")">Wanna subscribe?</a>

I will get http://mysiteweb.com/Subscription/Index which will give a 400 not found page instead of something like http://mywebsite.com/en/subscription (with the language id). 我将获得http://mysiteweb.com/Subscription/Index ,它将提供一个未找到400的页面,而不是诸如http://mywebsite.com/en/subscription (具有语言ID)之类的内容。

The Subscription page has been published through the admin panel so I guess it is possible to create an href on it without any hard coding? 订阅页面已通过管理面板发布,因此我想可以在没有任何硬编码的情况下在其上创建href。

Hope we have a N2CMS fan around.. 希望我们周围有一个N2CMS粉丝。

Thank for any help, 感谢您的帮助,

David 大卫

I finally found the answer. 我终于找到了答案。 You will be able to get the complete URL using the API given with the CMS. 您将能够使用CMS提供的API来获取完整的URL。

For instance, imagine you have a control called ChangePasswordViewModel which inherits from ContentItem then you have the associated controller. 例如,假设您有一个名为ChangePasswordViewModel的控件,该控件从ContentItem继承,然后您具有关联的控制器。 You will be able to get the full URL no matter the current language by doing this: 通过执行以下操作,无论当前使用哪种语言,您都可以获取完整的URL:

@{ 
var item = Find.Items
    .Where.Type.Eq(typeof(ChangePasswordViewModel)).And.State.Eq(ContentState.Published)
    .Select().SingleOrDefault();
}

And then <a href="@item.Url">Change password</a> 然后<a href="@item.Url">Change password</a>

To conclude, don't forget to add the ChangePasswordViewModel control in the admin panel section and everything will work fine using the API. 最后,请不要忘记在管理面板部分中添加ChangePasswordViewModel控件,并且使用API​​可以正常运行。

David 大卫

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM