Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Casper Andersen 126 posts 508 karma points
    Feb 19, 2015 @ 02:18
    Casper Andersen
    0

    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");

            }

        }

    }

    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));
        <a href="/events/[email protected]" class="linkEvent">
            <div class="customEvent">
                <div class="thumbnail">
                    <img src="@img.Url" alt="@img.Name">
                    <div class="caption">
                        <h3>@page.GetPropertyValue("name")</h3>
                        <p>@Html.ShortText(page.GetPropertyValue("description").ToString(),25)</p>
                    </div>
                </div>
            </div>
        </a>
    }
    I am still new to Umbraco so sorry for any newb mistakes

     

  • kristian schneider 190 posts 351 karma points
    Feb 19, 2015 @ 09:23
    kristian schneider
    0

    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

  • Casper Andersen 126 posts 508 karma points
    Feb 19, 2015 @ 16:08
    Casper Andersen
    0

    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:

    [InvalidOperationException: No route in the route table matches the supplied values.]
       System.Web.Mvc.Html.ChildActionExtensions.ActionHelper(HtmlHelper htmlHelper, String actionName, String controllerName, RouteValueDictionary routeValues, TextWriter textWriter) +602
       System.Web.Mvc.Html.ChildActionExtensions.Action(HtmlHelper htmlHelper, String actionName, String controllerName, RouteValueDictionary routeValues) +83
       System.Web.Mvc.Html.ChildActionExtensions.Action(HtmlHelper htmlHelper, String actionName, String controllerName) +10
       ASP._Page_Views_Events_cshtml.Execute() in c:\Users\364713\Documents\My Web Sites\KN Event\Giantgrandprix\Giantgrandprix\Views\Events.cshtml:9
       System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +197
       System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +103
       System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +76
       System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +256
       System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +107
       Umbraco.Core.Profiling.ProfilingView.Render(ViewContext viewContext, TextWriter writer) +93
       System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +291
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +13
       System.Web.Mvc.<>c__DisplayClass1a.<InvokeActionResultWithFilters>b__17() +23
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +245
       System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +22
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +245
       System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +22
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +176
       System.Web.Mvc.Async.<>c__DisplayClass2a.<BeginInvokeAction>b__20() +75
       System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult) +99
       System.Web.Mvc.Async.WrappedAsyncResult`1.End() +50
       System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27
       System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +14
       System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
       System.Web.Mvc.Async.WrappedAsyncResult`1.End() +55
       System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +39
       System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
       System.Web.Mvc.Async.WrappedAsyncResult`1.End() +55
       System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +29
       System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
       System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +25
       System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
       System.Web.Mvc.Async.WrappedAsyncResult`1.End() +55
       System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +31
       System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
       System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9657896
       System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
  • kristian schneider 190 posts 351 karma points
    Feb 19, 2015 @ 16:11
    kristian schneider
    0

    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


  • Casper Andersen 126 posts 508 karma points
    Feb 19, 2015 @ 18:07
    Casper Andersen
    0

    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"))

  • kristian schneider 190 posts 351 karma points
    Feb 19, 2015 @ 18:17
    kristian schneider
    100

    You Model is probably empty.

    So you might want to return something like:

     return PartialView("Event",new Umbraco.Web.Models.RenderModel(CurrentPage, CultureInfo.CurrentUICulture));
  • Casper Andersen 126 posts 508 karma points
    Feb 19, 2015 @ 18:20
    Casper Andersen
    0

    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 :)

  • kristian schneider 190 posts 351 karma points
    Feb 19, 2015 @ 18:24
    kristian schneider
    0

    No Worries.

    Returning a view with a custom model section might help you

     

  • Casper Andersen 126 posts 508 karma points
    Feb 21, 2015 @ 13:50
    Casper Andersen
    0

    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 :)

Please Sign in or register to post replies

Write your reply to:

Draft