Hi guys i have a small problem i was hoping you could help me with,to put it plainly i have a Template file called Events.cshtml that contains this
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage @using Giantgrandprix.App_Code @{ Layout = "~/Views/Shared/Master.cshtml"; } <div class="col-lg-12"> <div class="row eventWrapper"> @Html.Action("Index", "Event", null)) </div> </div> <div class="col-lg-12" style="padding: 0px;"> <div id="facebook_sidebar" class="col-lg-2 col-md-12 col-sm-12 col-xs-12 pull-left"><h2>Facebook</h2></div> <article id="article_master" class="col-lg-6 col-md-12 col-sm-12 col-xs-12 col-lg-offset-1"><h2>Main Content</h2> </article> <div id="sponsor_sidebar" class="col-lg-2 col-md-12 col-sm-12 col-xs-12 pull-right"><h2>Sponsorer</h2></div> </div> as you can see i am trying to call the Index method within my EventController that has this inside of it
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Umbraco.Web.Mvc;
namespace Giantgrandprix.Controllers
{
public class EventController : Controller
{
public PartialViewResult Index()
{
return PartialView("Event");
}
}
}
and i want it to return this Partial View everytime i call the Index method mostly so i can make a new method later on that will grab the Id i send along, the Partial View i want to call looks like this
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@using Giantgrandprix.App_Code
@foreach (var page in Model.Content.Children.Where(x => x.DocumentTypeAlias == "Event"))
{
var img = Umbraco.TypedMedia(page.GetPropertyValue<string>("image", recurse: true));
When i try and call the controller like so @Html.Action("Index", "Event")) or like this for that matter @Html.Action("Index", "Event", null)) i get this
No route in the route table matches the supplied values.
Bingo! That did the trick thanks alot :-D only thing now is i have no idea what you just did. But basically what i want to do is just display events and so on and when a user clicks an event i want to make a getsingleevent method in the controller that takes the id as the parameter and displays other stuff i am guessing this should not be a problem and most of all i am counting on not needing a model for any of this since i am not interacting with the database in any way ? Thanks a lot for the support means a lot to me :)
Thanks looked it over and after a good night sleep i found i needed to pass some Data to my controller and then get my controller to return the modded data i have a similar question i asked and answerede myself here for future reference
Returning PartialView from Controller
Hi guys i have a small problem i was hoping you could help me with,to put it plainly i have a Template file called Events.cshtml that contains this
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@using Giantgrandprix.App_Code
@{
Layout = "~/Views/Shared/Master.cshtml";
}
<div class="col-lg-12">
<div class="row eventWrapper">
@Html.Action("Index", "Event", null))
</div>
</div>
<div class="col-lg-12" style="padding: 0px;">
<div id="facebook_sidebar" class="col-lg-2 col-md-12 col-sm-12 col-xs-12 pull-left"><h2>Facebook</h2></div>
<article id="article_master" class="col-lg-6 col-md-12 col-sm-12 col-xs-12 col-lg-offset-1"><h2>Main Content</h2>
</article>
<div id="sponsor_sidebar" class="col-lg-2 col-md-12 col-sm-12 col-xs-12 pull-right"><h2>Sponsorer</h2></div>
</div>
as you can see i am trying to call the Index method within my EventController that has this inside of it
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Umbraco.Web.Mvc;
namespace Giantgrandprix.Controllers
{
public class EventController : Controller
{
public PartialViewResult Index()
{
return PartialView("Event");
}
}
}
Hi Casper.
Do you get an error or how do you struggle with your issue?
You might want to read up on how surface controllers work and MVC and umbraco in general. There are a few differences from working
with regular MVC
Best regards
Kristian
When i try and call the controller like so @Html.Action("Index", "Event")) or like this for that matter @Html.Action("Index", "Event", null)) i get this
No route in the route table matches the supplied values.
Stack trace if anyone wants to see it:
Let your eventcontroller inherit from the surface controller ie:
public class EventController : SurfaceController
Also check out https://our.umbraco.org/documentation/reference/Templating/Mvc/surface-controllers
Ok so far so good :) only problem i get now is
Object reference not set to an instance of an object.
foreach (var page in Model.Content.Children.Where(x => x.DocumentTypeAlias == "Event"))
You Model is probably empty.
So you might want to return something like:
Bingo! That did the trick thanks alot :-D only thing now is i have no idea what you just did. But basically what i want to do is just display events and so on and when a user clicks an event i want to make a getsingleevent method in the controller that takes the id as the parameter and displays other stuff i am guessing this should not be a problem and most of all i am counting on not needing a model for any of this since i am not interacting with the database in any way ? Thanks a lot for the support means a lot to me :)
No Worries.
Returning a view with a custom model section might help you
Thanks looked it over and after a good night sleep i found i needed to pass some Data to my controller and then get my controller to return the modded data i have a similar question i asked and answerede myself here for future reference
https://our.umbraco.org/forum/umbraco-7/using-umbraco-7/61478-Getting-custom-Model,-Controller-and-View-to-interact
Thanks for all the help :)
is working on a reply...