+1-888-365-2779
Try Now
More in this section

Forums / Bugs & Issues / MVC: Model is null in controller when in hybrid mode

MVC: Model is null in controller when in hybrid mode

4 posts, 0 answered
  1. Brian
    Brian avatar
    7 posts
    Registered:
    28 Jan 2014
    23 Feb 2014
    Link to this post
    I am building my first widget in VS 2010, SF 6.3 (demo).  I followed the steps from a Telerik video on YouTube: http://www.youtube.com/watch?v=KRm7kDskUjg

    I have two page templates, one that is hybrid, one that is pure MVC.  When I step through the code in hybrid mode, it's evident the model is null.  In pure MVC mode, the model is received correctly by the controller.  

    Here is my Controller:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using SitefinityWebApp.Mvc.Models;
    using Telerik.Sitefinity.Modules.News;
    using Telerik.Sitefinity.Mvc;
     
    namespace SitefinityWebApp.Mvc.Controllers
    {
        [ControllerToolboxItem(Name="NewsForm",Title="News Form",SectionName="MVCTools")]
        public class NewsFormController : Controller
        {
            public ActionResult Index()
            {
                return View("NewsFormView");
            }
     
            [HttpPost]
            public ActionResult Index(NewsModel model)
            {
                var newsManager = NewsManager.GetManager();
                var newsItem = newsManager.CreateNewsItem();
     
                newsItem.Title = model.Title;
                newsItem.Content = model.Content;
                newsItem.UrlName = model.UrlName;
     
                newsManager.RecompileItemUrls(newsItem);
                newsManager.SaveChanges();
     
                return View("Success");
            }
        }
    }

    Here is my Model:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
     
    namespace SitefinityWebApp.Mvc.Models
    {
        public class NewsModel
        {
            public string Title { get; set; }
            public string Content { get; set; }
            public string UrlName { get; set; }
        }
    }

    Here is my View:
    @using Telerik.Sitefinity.UI.MVC
    @using SitefinityWebApp.Mvc.Models
    @model NewsModel
     
    @using (Html.BeginFormSitefinity())
    {
        @Html.EditorForModel()
        <input type ="submit" value="Create news item" />
    }

    Any ideas on what I am missing?  It seems to work fine in the Telerik screencast on youtube.

    Peace,
    Brian

  2. Peter
    Peter avatar
    36 posts
    Registered:
    03 Oct 2016
    24 Feb 2014
    Link to this post
    Hi Brian,

    Your code looks all right. I have tried it at my end using the latest version 6.3.5020 and It worked exactly as it is supposed to - consistent in both hybrid and pure modes.

    Do you have any exception when using the hybrid mode or you just go to the Success view with no NewsItem created? Also, what input have you used? Anything you can share to make me reproduce it will be much appreciated

    I saw that you are observing abnormal high CPU usage when you application restarts. That is due to the Razor views we compile at run-time when the application starts. With the latest build those are pre-compiled and the CPU usage is back to normal.

    Perhaps you can upgrade to the latest hot fix and and try the same widget on the latest version, which is the same as mine  (link here).

    Regards,
    Peter
    Telerik
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
  3. Forrest
    Forrest avatar
    3 posts
    Registered:
    03 Aug 2012
    16 Jun 2014
    Link to this post

    I'm actually having the same issue in version 7.  Anyone know if this is a known issue or not?  No matter what I try the model is null.  I can pull the values out of a FormCollection but I'd rather not.

    Thanks!
    Jason

  4. Svetoslav Manchev
    Svetoslav Manchev avatar
    735 posts
    Registered:
    07 Dec 2016
    18 Jun 2014
    Link to this post
    Hello Jason,

    I have tested the code below on Sitefinity 7 hybrid mode and it returns the model as expected (screenshot).

    Could you please provide us with your code in order to inspect and test it?

    Regards,
    Svetoslav Manchev
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
4 posts, 0 answered