publicclassTextPageController : RenderMvcController
{
publicoverrideActionResult Index(RenderModel model)
{
//we will create a custom modelvar customModel = ContentHelper.GetCurrentContent() asTextPage;
//Example for 4.10://get the template name from the route values:var template = ControllerContext.RouteData.Values["action"].ToString();
//return an empty content result if the template doesn't physically //exist on the file systemif (!EnsurePhsyicalViewExists(template))
{
return Content("");
}
//return the current template with an instance of MyCustomModelreturn View(template, customModel);
}
}
When I call the page I get this ysod and I wonder why since the model returned in controller is TextPage and the model declared in razor view is TextPage.
You give the wrong object back, i stopped using the index to override and use my own controller like this
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using Umbraco.Web.Models; using Umbraco.Web.Mvc; using umbraco.cms.businesslogic.template; using ViewModel;
namespace W3S.Controllers { public class HomeController : W3S.Models.Master { public ActionResult Home(RenderModel Model) { HomeViewModel HVM = new HomeViewModel(); HVM.UmbracoModel = Model;
return View(HVM); }
}
} namespace ViewModel { public class HomeViewModel { public RenderModel UmbracoModel { get; set; } } }
Pass strongly type model in razor view
Hi everyone,
I'm trying to implement strongly type model in controller using Umbraco 4.10 and I can't figure what I'm doing wrong.
Here is my razor view:
And here is my custom controller :
When I call the page I get this ysod and I wonder why since the model returned in controller is TextPage and the model declared in razor view is TextPage.
Thanks per advance.
DDU
Here is the error :
Forget about it, the following line was the culprit :
You give the wrong object back, i stopped using the index to override and use my own controller like this
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Umbraco.Web.Models;
using Umbraco.Web.Mvc;
using umbraco.cms.businesslogic.template;
using ViewModel;
namespace W3S.Controllers
{
public class HomeController : W3S.Models.Master
{
public ActionResult Home(RenderModel Model) {
HomeViewModel HVM = new HomeViewModel();
HVM.UmbracoModel = Model;
return View(HVM);
}
}
}
namespace ViewModel {
public class HomeViewModel {
public RenderModel UmbracoModel { get; set; }
}
}
@model ViewModel.HomeViewModel
@{
ViewBag.Title = "Test";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>@Model.UmbracoModel.Content.GetProperty("titel").Value</h2>
<div>@Html.Raw((string)Model.UmbracoModel.Content.GetProperty("body").Value)</div>
I'm busy with the same problem but i stumbled upon this one http://our.umbraco.org/forum/core/general/36526-U411-Looks-like-NodeUrl-functionality-is-broken?p=0
So strong typed objects you cannot get a url... pretty big problem for me.
is working on a reply...