Using Mvc Widgets with Layout and Form elements
I am attempting to create the following Mvc Widget in Sitefinity:
@model SitefinityWebApp.Mvc.Models.LoginModel
@
Layout = "~/Mvc/Views/Shared/_Layout.cshtml";
ViewBag.Title = "Edit Profile Login";
ViewBag.MobileUrl = "http://www.homepage.com/mobile";
ViewBag.HomeUrl = "http://www.homepage.com";
@section Header
<
h2
>@ViewBag.Title</
h2
>
<
a
href
=
"@ViewBag.HomeUrl"
data-role
=
"button"
data-icon
=
"home"
data-mini
=
"true"
data-inline
=
"true"
>Home</
a
>
<
a
href
=
"@ViewBag.MobileUrl"
data-role
=
"button"
data-icon
=
"gear"
data-mini
=
"true"
data-inline
=
"true"
>Mobile Home</
a
>
@using (Html.BeginForm())
@Html.AntiForgeryToken()
@Html.ValidationSummary()
<
ul
data-role
=
"listview"
data-inset
=
"true"
>
<
li
data-role
=
"fieldcontain"
>
@Html.LabelFor(m => m.UserName)
@Html.TextBoxFor(m => m.UserName)
</
li
>
<
li
data-role
=
"fieldcontain"
>
@Html.LabelFor(m => m.Password)
@Html.PasswordFor(m => m.Password)
</
li
>
<
li
data-role
=
"fieldcontain"
>
<
input
type
=
"submit"
value
=
"Log in"
/>
</
li
>
</
ul
>
When I attempt to render the Mvc Widget in Sitefinity, it errors out and gives me an error such as the following:
Type : System.Web.HttpException, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Message : Type 'ASP._Page_Mvc_Views_ClassRegistration_Index_cshtml' does not inherit from 'System.Web.WebPages.WebPage'.
This works just fine in a standard ASP.NET MVC application, so I am not sure what is not working. Perhaps there are numerous limitations with MVC in Sitefinity? I am using Hybrid mode. Does Hybrid mode not support MVC Layouts and various other MVC Form elements such as ViewBag?
Please advise.
Thanks.
Hello Samir,
I have just tested it on my side and I was not able to reproduce the issue.
I have created a _Layout.cshtml file which I want to use as a base template in my pages/views and defined the “Header” section of content that will be rendered by calling the RenderSection(string sectionName, bool required) helper method within the _Layout.cshtml.
Here is the sample markup of the _Layout.cshtml file:
<!DOCTYPE html>
<
html
xmlns
=
"http://www.w3.org/1999/xhtml"
>
<
head
>
<
title
>ViewBag.Title</
title
>
</
head
>
<
body
>
<
div
>This is my base Layout Template</
div
>
<
div
>
<
div
>This is the Header section which will be rendered from the View</
div
>
<
div
id
=
"header"
>
@RenderSection("Header", false)
</
div
>
</
div
>
</
body
>
</
html
>
@model SitefinityWebApp.Mvc.Models.MyModulesMVCWidgetModel
@
Layout = "~/Mvc/Views/Shared/_Layout.cshtml";
ViewBag.Title = "Edit Profile Login";
ViewBag.MobileUrl = "http://www.homepage.com/mobile";
ViewBag.HomeUrl = "http://www.homepage.com";
@section Header
<
h2
>@ViewBag.Title</
h2
>
<
a
href
=
"@ViewBag.HomeUrl"
data-role
=
"button"
data-icon
=
"home"
data-mini
=
"true"
data-inline
=
"true"
>Home</
a
>
<
a
href
=
"@ViewBag.MobileUrl"
data-role
=
"button"
data-icon
=
"gear"
data-mini
=
"true"
data-inline
=
"true"
>Mobile Home</
a
>
I am encountering the same problem. It's extremely aggravating to be using a much-advertised "MVC page plugin feature" when I have to chase down obscure references to solve what you claim is more or less "plug and play."
We are using the current trial version, as we are currently deciding whether or not to invest in this product. Do you have a solution that works?
Hello Benjamin,
Can you please provide more details about the exact use case scenario? What you would like to achieve and what you have done on your side so far? This way I will get better picture of the problem and will be able to further help you.
Regards,
Sabrie Nedzhip
Telerik