I understand that what I'm asking here might be outside what this forum is all about but I'm stuck (well I never really got started) and will try anything!!
I've got an Umbraco v7.2.4 install and I'm trying to display some data on a template using MVC but I cannot get it to work. So apologies for the long winded post but I thought that I'd better give you everything.
In my Models I've got:
using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace SxWhite.Models { public class CoursesViewModel { public int iNodeID { get; set; } public string CourseTitle { get; set; } public string CourseDesc { get; set; } } }
In my controller: *Ultimately I need to populate this 'list' from my Content in Umbraco but that's another matter!
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using Umbraco.Web.Mvc; namespace SxWhite.Controllers { public class CoursesController : SurfaceController { // // GET: /Courses/ public ActionResult Index() { var courses = new List<CoursesViewModel> { new CoursesViewModel {iNodeID=1, CourseDesc="Description 1", CourseTitle="Title 1"}, new CoursesViewModel {iNodeID=2, CourseDesc="Description 2", CourseTitle="Title 2"} }; return PartialView("courses", new CoursesViewModel()); } } }
You are passing through a new model and not the list of courses. Pass through the courses also you will need to update your view to acccept List<CoursesViewModel> although a better of doing this is to hijack the Courses route see https://our.umbraco.org/Documentation/Reference/Mvc/custom-controllers
So your saying that I should change my controller to return PartialView("courses", courses); but I'm not sure what I need to do to my view to accept List<CoursesViewModel>.
Do you mind just helping an idiot a little more please?
Thanks,
Craig.
I've bookmarked that link and I'll read through a little later.
Displaying Data using MVC
Hi folks,
I understand that what I'm asking here might be outside what this forum is all about but I'm stuck (well I never really got started) and will try anything!!
I've got an Umbraco v7.2.4 install and I'm trying to display some data on a template using MVC but I cannot get it to work. So apologies for the long winded post but I thought that I'd better give you everything.
In my Models I've got:
In my controller: *Ultimately I need to populate this 'list' from my Content in Umbraco but that's another matter!
My view:
And in my template I'm calling it with:
@Html.Action("Index", "Courses")
I'm not getting an error at all but nothing is being displayed on the page and I'm just going round in circles.
Any help would be massively massively massively appreciated.
thanks,
Craig
Craig,
You are passing through a new model and not the list of courses. Pass through the courses also you will need to update your view to acccept List<CoursesViewModel> although a better of doing this is to hijack the Courses route see https://our.umbraco.org/Documentation/Reference/Mvc/custom-controllers
Hi Ismail,
Thanks for your time.
So your saying that I should change my controller to return PartialView("courses", courses); but I'm not sure what I need to do to my view to accept List<CoursesViewModel>.
Do you mind just helping an idiot a little more please?
Thanks,
Craig.
I've bookmarked that link and I'll read through a little later.
Craig,
In you view change
to
then you will need to loop through your courses and write out data for each one.
Regards
Ismail
AWESOME!
You are a star!
Now all I gotta do is work for how to build the list using the content in my Umbraco build.....
Thanks!
Hello,
If you want some MVC examples have a look at the Hybrid Framework.
Jeroen
Cheer Jeroen,
I shall have a butchers.
is working on a reply...