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

Forums / Developing with Sitefinity / Using Mvc Widgets with Layout and Form elements

Using Mvc Widgets with Layout and Form elements

4 posts, 0 answered
  1. Samir Vaidya
    Samir Vaidya avatar
    261 posts
    Registered:
    05 Feb 2005
    05 Feb 2015
    Link to this post

    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.

  2. Sabrie Nedzhip
    Sabrie Nedzhip avatar
    534 posts
    Registered:
    05 Dec 2016
    09 Feb 2015
    Link to this post
    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>
    <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>

    After that in the View of my MVC widget I specified that I will use the _Layout.cshtml as a layout template and then implemented the “Header” section. Here is the markup of my MVC widget view:

    @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 also sending a video for your convenience demonstrating the behavior on my side.

    Can you please provide more details about the exact use case scenario on your side? Are you using Feather widgets? What is the exact version of your Sitefinity project? Please let me know some detailed steps to reproduce the issue on my side?

    In addition to this, I searched over the internet and found the following resources where a similar issue has been discussed:

    http://stackoverflow.com/questions/10460913/razor-view-type-does-not-inherit-from-system-web-webpages-webpage
    http://blog.jsinh.in/man-003-webpages-enabled-appsetting-mvc/#.VNioXJ2UcSw

    Regards,
    Sabrie Nedzhip
    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. Benjamin
    Benjamin avatar
    4 posts
    Registered:
    10 Aug 2015
    06 Nov 2015 in reply to Sabrie Nedzhip
    Link to this post

    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?

     

  4. Sabrie Nedzhip
    Sabrie Nedzhip avatar
    534 posts
    Registered:
    05 Dec 2016
    11 Nov 2015
    Link to this post
    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
     
    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