Render different partial view for different Url Page
I have 2 forms and 2 pages. I want to use the same document type and render different form on the page, depending on which page the users will land on.
Simple but difficult task for me as of yet. I am getting the page ID and setting it to a variable, but when I check it in the if statement it's complaining that it can't conver type "bool" to IPublished.Content....
@inherits Umbraco.Web.Mvc.UmbracoViewPage<CtaForm>
@{
var thunderPage = Umbraco.TypedContent(2209);
var downloadGuidePage = Umbraco.TypedContent(2214);
}
@if (thunderPage = true)
{
@Html.Partial("Forms/_CtaForm", new CitytalkWebsite.Models.ContactForm())
}
else if (downloadGuidePage = true))
{
@Html.Partial("Forms/_DownloadPageForm", new CitytalkWebsite.Models.ContactForm())
}
You can just use Model.Id in ViewPage, Model.Content.Id is if you use TemplatePage, if I got this right.
I changed the code with Model.Id, no errors on build or in console, both pages load fine but the forms are not rendered on them at all? :( Not sure how to proceed further....thinking about giving up and just create another document type that will render the second form on download guide page.
Render different partial view for different Url Page
I have 2 forms and 2 pages. I want to use the same document type and render different form on the page, depending on which page the users will land on.
Simple but difficult task for me as of yet. I am getting the page ID and setting it to a variable, but when I check it in the if statement it's complaining that it can't conver type "bool" to IPublished.Content....
If you need to compare to specific page, you can:
Did not check spelling :) Bare in mind this is not a very scallable solution.
Other senario could be to use a macro with parameter to pick correct form
Hmm, your solution gives me this error:
The name 'CurrentPage' does not exist in the current context
Sry.. wasn't to sharp there :)
When you use UmbracoViewPage CurrentPage isn't awailable
Use Model.Content.Id to get Id of current
or just add
No worries, thanks a lot for trying to help.
You can just use Model.Id in ViewPage, Model.Content.Id is if you use TemplatePage, if I got this right.
I changed the code with Model.Id, no errors on build or in console, both pages load fine but the forms are not rendered on them at all? :( Not sure how to proceed further....thinking about giving up and just create another document type that will render the second form on download guide page.
An alternative solution would be to create another template for your document type.
For example, you could have a generic
ContactForm
Template and then aDownloadPageForm
Template which both contain the relevant partial view.In this way, you won't need to get the page id, but instead just set the appropriate template in the back-end.
ContactForm.cshtml
DownloadPageForm.cshtml
is working on a reply...