Copied to clipboard

Flag this post as spam?

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


  • Bill Haggerty 43 posts 177 karma points
    Jun 27, 2016 @ 21:18
    Bill Haggerty
    0

    Making a RenderModel more specific ( More an MVC question, but still Umbraco related)

    This is more an ASP.Net MVC question...

    namespace Umbraco.Extensions.Controllers
    {
        public class ImplementationDashboardController : RenderMvcController
        {
            public ActionResult ImplementationDashboard(RenderModel model)
            {
                var tableModel = new TableEditorModel();
                tableModel =
                    (TableEditorModel)model.Content.ContentSet.ElementAt(3).Properties.ElementAt(0).Value;
                return CurrentTemplate(tableModel);
            }
        }
    }
    

    What I am trying to do is accept a model that Umbraco is giving, but just give the view the TableEditorModel.

    This code works, but I don't think it is very good.

    Any suggestions on how to improve this line ?? Or maybe I should do this differently??

     tableModel =
                    (TableEditorModel)model.Content.ContentSet.ElementAt(3).Properties.ElementAt(0).Value;
    

    Thanks !!! Bill

  • David Peck 687 posts 1863 karma points c-trib
    Jun 28, 2016 @ 14:14
    David Peck
    0

    From an MVC perspective I don't see what you're doing is wrong. If you're view inherits from:

    UmbracoViewPage<TableEditorModel>
    

    then you'll still have access to the UmbracoHelper.

    As for your long lone, it is rather messy but I'm not sure what you're trying to actually achieve, but I wonder if you're not after something more like:

    using Umbraco.Web;
    model.Content.Children().First(c => c.DocumentTypeAlias == "someDocumentTypeAlias").GetPropertyValue<TableEditorModel>("somePropertyAlias")
    
  • Bill Haggerty 43 posts 177 karma points
    Jun 28, 2016 @ 18:53
    Bill Haggerty
    0

    Thanks, David !!

    That is what I was looking for. To me, using numbers like "3" and "0" like in my original case is brittle code.

Please Sign in or register to post replies

Write your reply to:

Draft