using System.Web.Mvc;
using Umbraco.Web.Mvc;
using My.Site.Models;
namespace My.Site.Controllers
{
public class FeatureBlockController : SurfaceController
{
[ChildActionOnly]
public ActionResult RenderFeatureBlock()
{
var featureBlock = new FeatureBlockModel { Desc = "Welcome", Media = "/media/test.jpg", Title = "Hello" };
return PartialView("FeatureBlock", featureBlock);
}
}
}
Model:
namespace My.Site.Models
{
public class FeatureBlockModel
{
public string Title {get; set;}
public string Desc {get; set;}
public string Media {get; set;}
}
}
Note that this is almost exactly what you would do in "normal" MVC so if you need more info make sure to also look at resources about simple ASP.NET MVC.
So basically this code is work, many thanks before. From what i see when using surface controller we must use [ChildActionOnly] tag and create the partial view ?
Simple Example of SurfaceController ?
Umbraco version 6.1.6
Is there anyone can help me how to user surfacecontroller the simplest way, from model to controller and the view ?
This is what i had done :
- Create Model with name FeatureBlock.cs ( some properties e.g title, desc, media)
- Create Controller FeatureBlockController without suffix "SurfaceController"
This controller inherit from SurfaceController
the index is :
public class FeatureBlockController : Umbraco.Web.Mvc.SurfaceController
{
public ActionResult Index(RenderModel model)
{
return Content("asd");
}
}
I already spent a day tinkering about this and still no luck. But when i use Umbraco.Web.Mvc.RenderMVCController the index controller is hit.
1. So give me explantion when to user SurfaceController and when to use RenderMVCController ?
2. Help me with the simple example Hello World from index action.
Controller:
Model:
View (~/Views/FeatureBlock/FeatureBlock.cshtml):
In you template, call the following:
Note that this is almost exactly what you would do in "normal" MVC so if you need more info make sure to also look at resources about simple ASP.NET MVC.
Hope this helps!
Thanks Sebastiaan.
So basically this code is work, many thanks before. From what i see when using surface controller we must use [ChildActionOnly] tag and create the partial view ?
Will be read again the documentaion. Thanks again
Ah yes, I left that in there as best practice, you don't HAVE to use it, but it makes sense, read more about ChildActionOnly here: http://stackoverflow.com/questions/10253769/using-childactiononly-in-mvc
Comment author was deleted
There's also a chapter on umbraco.tv about surface controllers http://umbraco.tv/videos/developer/fundamentals/surface-controllers/introduction/ :) teaches you the basics (including client and server validation) + you can download the completed example
Thanks Tim and sebastiaan will check that out. :D.
Sebastiaan,
Suffix the surfacecontroller with SurfaceController is no longer needed?
https://our.umbraco.org/documentation/reference/routing/surface-controllers ?
It's not, which will be included in the next documentation update.
is working on a reply...