Real MVC Implementation - View does not depend on Umbraco implementations
I have followed this nice tutorial which explains how you can take even more advantage of using Umbraco as a content delivery system.
Tutorial MVC Umbraco =>
Your model and views should not depend on specific Umbraco implementations which is a huge advantage for real front-end developers.
Controller:
public class FrontPageController : MasterDocTypeController
{
public ActionResult FrontPage(RenderModel renderModel)
{
FrontPageModel blobsList = renderModel.Content.Map();
blobsList.FillBlobList(storageContainer.ListBlobs(useFlatBlobListing: true));
return View(blobsList);
}}
View:
Model:
public class FrontPageModel:MasterModel
{
public string Title { get; set; }
public IHtmlString BodyText { get; set; }
public string Answer { get; set; }
public List<CloudFile> Files { get; set; }
//CONSTRUCTOR
public FrontPageModel()
: this(null)
{
Files = new List<CloudFile>();
}
public FrontPageModel(IEnumerable<IListBlobItem> list)
{
FillList(list);
}
//METHODS
public void FillBlobList(IEnumerable<IListBlobItem> list)
{
FillList(list);
}
}
As you can see, most of the things are the same as in tutorial.
When playing around, i faced an issue with the Actionlink in my view.
<a href="">Upload Another File</a>
The link doesn't work because the HREF value has not been populated.
This link should redirect the page to the same Controller (FrontPage).
It seems this is causing the problem, because it is working when redirecting to a "surfacecontroller" instead of "renderMVCcontroller".
I feel that redirecting to other controller is breaking the normal MVC Structure.
Is it right to say that one can not redirect to other pages when action is defined inside "rendermvccontroller"?
How would you resolve this issue?
Extension to my first post => Should we really use surface controller when we have @HTML.ActionLink("Upload Another File,UploadFile,FrontPage") on our page ?
Currently, when i want to retrieve data from the CMS itself, i'am using RenderMVCController which is giving a RenderModel as a argument in your constructor. When using this controller, how can you manage navigation between pages?
I don't know if you had your question answered, but for further reference:
You cannot use Html.ActionLink, Url.Action or Ajax.ActionLink to link to a page. Why?
First of, umbraco content is content, not actions. All requests are routed to the controllers and actions. Meaning content is delivered by parsing urls -> controller + action.
To create a link to an other page, you must simply provide the url in your model like:
You can, however, use Html.ActionLink, Url.Action, Ajax.ActionLink, to get a URL to a surface controller action and/or API controller action. But not RenderMvcController actions.
Real MVC Implementation - View does not depend on Umbraco implementations
I have followed this nice tutorial which explains how you can take even more advantage of using Umbraco as a content delivery system. Tutorial MVC Umbraco => Your model and views should not depend on specific Umbraco implementations which is a huge advantage for real front-end developers.
Controller:
View:
Model:
As you can see, most of the things are the same as in tutorial.
When playing around, i faced an issue with the Actionlink in my view.
The link doesn't work because the HREF value has not been populated. This link should redirect the page to the same Controller (FrontPage). It seems this is causing the problem, because it is working when redirecting to a "surfacecontroller" instead of "renderMVCcontroller".
I feel that redirecting to other controller is breaking the normal MVC Structure. Is it right to say that one can not redirect to other pages when action is defined inside "rendermvccontroller"? How would you resolve this issue?
Extension to my first post => Should we really use surface controller when we have @HTML.ActionLink("Upload Another File,UploadFile,FrontPage") on our page ?
Currently, when i want to retrieve data from the CMS itself, i'am using RenderMVCController which is giving a RenderModel as a argument in your constructor. When using this controller, how can you manage navigation between pages?
Hi,
I'm the author of the post you've linked to.
I don't know if you had your question answered, but for further reference:
You cannot use Html.ActionLink, Url.Action or Ajax.ActionLink to link to a page. Why?
First of, umbraco content is content, not actions. All requests are routed to the controllers and actions. Meaning content is delivered by parsing urls -> controller + action.
To create a link to an other page, you must simply provide the url in your model like:
model.LinkToSomePage = CurrentPage.Children.First().Url;
Or whatever page you want to link to.
Here's an answer that clearifies it a bit more: http://stackoverflow.com/a/18313882
You can, however, use Html.ActionLink, Url.Action, Ajax.ActionLink, to get a URL to a surface controller action and/or API controller action. But not RenderMvcController actions.
Hope that clearifies it for you.
is working on a reply...