MVC: Model is null in controller when in hybrid mode
I am building my first widget in VS 2010, SF 6.3 (demo). I followed the steps from a Telerik video on YouTube: www.youtube.com/watch
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"
);
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
;
@
using
Telerik.Sitefinity.UI.MVC
@
using
SitefinityWebApp.Mvc.Models
@model NewsModel
@
using
(Html.BeginFormSitefinity())
@Html.EditorForModel()
<input type =
"submit"
value=
"Create news item"
/>
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
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
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