" public class HomeController : RenderMvcController
public ActionResult Index()
{
var model = new HomeModel();
return View(model);
}
}"
and model is
public class HomeModel : RenderModel
{
public HomeModel() : base(UmbracoContext.Current.PublishedContentRequest.PublishedContent) { }
public string bodytext { get; set; }
public string headline { get; set; }
}
i create DocumentType at umbraco backoffice with (property ) "bodytext" and another with "headline " and finaly a create content and publish but anything change just whitesite
public class HomeController : RenderMvcController
public ActionResult Index(RenderModel model)
{
var homeModel = new HomeModel(model.Content, CultureInfo.CurrentCulture);
return CurrentTemplate(homeModel);
}
}
and for your Model
public class HomeModel : RenderModel
{
public HomeModel(IPublishedContent content, CultureInfo culture) : base(content,culture) { }
public string bodytext { get; set; }
public string headline { get; set; }
}
Your custom model contructure can then take in the relevant IPublishedContent and cultureInfo and pass this to the Base RenderModel, so the underlying Umbraco stuff is available via Model.Content but you can then add to your custom properties in the controller
yes allias is Home if on return actiton is set Return conttnt("test ") it's ok but, i don not understand why model do not working ? Strongly typed view syntax is ok .
My umbraco version is 7.3.0. I make sure I have created a document type and it has corresponding templates but still I cant get it to work.
what else could I have missed? any help would be appreciated. thanks!
Here is my code:
Controller:
using prc.web.Models;
using Umbraco.Web.Mvc;
using Umbraco.Web.Models;
namespace myproject.Controller
{
public class CatalogController: RenderMvcController
{
// GET: Books
public override ActionResult Index(RenderModel model)
{
//return View();
return base.Index(model);
}
}
}
Model :
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Runtime.Serialization;
using Umbraco.Web;
using Umbraco.Web.Models;
using Umbraco.Core.Models;
namespace myproject.web.Models
{
public class Catalog : RenderModel
{
public Catalog(IPublishedContent content)
: base(content)
{ }
public int BookId { get; set; }
}
}
Did that already. is there any configuration that could allow or disallow custom controller? I did as exactly what the tutorial and your suggestions says but I cant I hijacked any controller. :(
PS. somebody started this project so I suspect he must have change any config. sorry kinda new to Uumbraco.
Costom controller does not working
Hi i create a custom controller
and model is
i create DocumentType at umbraco backoffice with (property ) "bodytext" and another with "headline " and finaly a create content and publish but anything change just whitesite
home template
if i set
<p>@Model.Content.GetPropertyValue("Headline")</p>
this syill workBest Esmeraldi
try for your controller:
and for your Model
Your custom model contructure can then take in the relevant IPublishedContent and cultureInfo and pass this to the Base RenderModel, so the underlying Umbraco stuff is available via Model.Content but you can then add to your custom properties in the controller
Thanx marc but still not working....
best Esmeraldi
Hi Esmeraldi
What is the alias of your document type ?
home ?
If you set a breakpoint on the controller, does it get hit ? when you make a request to the url for the homepage ?
Hi Marc
yes allias is Home if on return actiton is set Return conttnt("test ") it's ok but, i don not understand why model do not working ? Strongly typed view syntax is ok .
Isn't Index a virtual method in RenderMvcController?
e.g.
James thanx for reply yes i try but nothing.. again i thing the problem is the
model
can not access property .... :(Hi,
add this line to your Controller before returning the View:
Also Esmeraldi
What has the home doctype setup in Umbraco to use as a template ?
In your code you return View(model) which View is it returning ? and does the home doctype setup for this template ?
When you set a break point on the controller, has your HomeModel got any properties before you step over and return the view ?
Hi guys, I have the same issue. I have been following the instructions from this docu: https://our.umbraco.org/documentation/reference/routing/custom-controllers as well as from this source: https://gist.github.com/nul800sebastiaan/8641249
My umbraco version is 7.3.0. I make sure I have created a document type and it has corresponding templates but still I cant get it to work.
what else could I have missed? any help would be appreciated. thanks!
Here is my code:
Controller:
Model :
View:
Hi Francisco
It looks like your view is expecting a custom model called Catalog that should inherit from RenderModel.
Which you have created.
With the custom BookId Property.
However when you hijack the route here:
You are only passing RenderModel to the view not your custom class.
Try:
to pass your custom model to the view that is expecting it.
regards
marc
Hi Marc,
I tried your code, but my page is still displaying the view coming from the umbraco. :(
Hi Francisco
Your view will need to inherit UmbracoViewPage
so
regards
Marc
Did that already. is there any configuration that could allow or disallow custom controller? I did as exactly what the tutorial and your suggestions says but I cant I hijacked any controller. :(
PS. somebody started this project so I suspect he must have change any config. sorry kinda new to Uumbraco.
many thanks!
is working on a reply...