Using webform master page in razor view - asp.net-mvc-3

I have tried implementing this, but the extension methods are not working when I rewrite them in VB. I am trying to use a corporate master page in my MVC3 application. Right now I have my .Master and my .ascx page. I am confused on how to get it to show in my razor view.
my .ascx page:
<%# control Language="VB" Inherits="System.Web.Mvc.ViewUserControl" %>
<asp:Content ID="Content" ContentPlaceHolderID="ContentArea" runat="server">
<div>
Hello World
</div>
</asp:Content>
When I run it, it gives me this error: Content controls have to be top-level controls in a content page or a nested master page that references a master page.
I use my _ViewStart.vbhtmlto call on the .ascx page.

Trying to hack webforms objects to work with MVC3 is only going to cause you trouble down the road. Redo the file as an MVC3 layout using razor.
Edit: added
Layout File Tutorials:
Making layout pages
Understanding Layout Files
Layouts and Sections

Related

How not to be confined into content area... full size web app on Joomla

I am currently creating an Intranet ERP application that will integrate an already existing corporate Joomla 3.1 based web site.
The extension i made so far only has one default controller php file and everything is made using a JavaScript UI framework. (i.e. jqWidgets) So i am not using model, views, helpers.
The other php files are there to respond to the client side interface AJAX requests.
So i mainly need Joomla for the user authentication and session control features but i dont want it to confine my extensions output to the content area... i need the entire document surface... no menu, no module columns, no nothing !
Can it be done ?
Two ways
component.php in the template will show only the component's output add &tmpl=component to your urls
Make a custom template that only outputs the component
<html>
<head>
<!-- put what scripts stylesheets you need etc//-->
</head>
<body>
<jdoc:include type="component" />
</body>
</html>

Customize Layout templates In MVC3

I known There is a default _Layout.cshtml file in Asp.net MVC just like MasterPage in Asp.net Web Site. Can I define multiple layout templates in my MVC app? If so ,How to make it? Please give me some code example . Thanks.
You can create multiple Layout pages and use it in differnt views. You may mention the new layout pages inside your views by mentioning the Layout property in your views.
Create a new View and name it as _AdminLayout.cshtml under Views/Shared folder. You may create your HTML markup for your master page template there. Make sure you have #RenderBody() section in your Layout page so that the content of your normal views will be replaced here when it renders.
<html>
<head>
</head>
<body>
<h1>My new Layout</h1>
#RenderBody()
</body>
</html>
And if you want to use this Layout in a view, you can do it like this
#{
Layout = "~/Views/Shared/_AdminLayout.cshtml";
}
<p>The content here will be present inside the render body section of layout</p>
If you want to use the new Layout for all the Views by default without explicitly mentioning like the above code, you can do it in the Views/_ViewStart.cshtml file
#{
Layout = "~/Views/Shared/_AdminLayout.cshtml";
}

Mixing Razor Views and Web Forms Master Pages

I'm attempting to do what Scott Hanselman describes below:
http://www.hanselman.com/blog/MixingRazorViewsAndWebFormsMasterPagesWithASPNETMVC3.aspx
I have a Web Form user control with code behind that is called from the Web Form and Razor Master Pages that is not working in the Razor layout:
<div id="navtop">
#{ Html.RenderPartial("~/Controls/MasterPageMenu.ascx"); }
</div>
The user control contains the following:
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="MasterPageMenu.ascx.cs" Inherits="Controls.MasterPageMenu" %>
I get the error:
The view at '~/Controls/MasterPageMenu.ascx' must derive from ViewPage, ViewPage, ViewUserControl, or ViewUserControl.
What have I missed in getting this to work in the Razor view world?
This should work, just make sure that your partial derives from ViewUserControl:
<%# Control
Language="C#"
Inherits="System.Web.Mvc.ViewUserControl"
%>
Remember that using server side controls in ASP.NET MVC is not something that's recommended even with the WebForms view engine and not something that you should even be attempting to do. In ASP.NET MVC you have layouts (master pages if you use WebForms view engine), views and partials. That's all. User controls belong to classic WebForms, not to ASP.NET MVC.

MVC Project errors after adding .ascx control

I've tried to add a .ascx user control to my EditorTemplates but doing so causes a hundred erros to pop up in my MVC 3 project. Every reference to "System." errors as "is not defined" and the compiler wants me to update them to "Global.System."
Can anyone tell me why adding the user control does this?
Thank you
UPDATE:
If i take out the code-behind files that are automatically created (and I don't think I need) then the problems seem to resolve. Very interesting...
User controls (stuff with runat="server") is not something that should be used in ASP.NET MVC application. They usually rely on Postbacks and ViewState which are notions that no longer exist in ASP.NET MVC. You could use an ascx partial/editor template and invoke it from a Razor view. So for example let's suppose that you have the following partial:
<%# Control
Language="C#"
Inherits="System.Web.Mvc.ViewUserControl<AppName.SomeViewModel>" %>
<%= Html.LabelFor(x => x.Foo) %>
<%= Html.TextBoxFor(x => x.Foo) %>
You could include it from a Razor view like this:
#Html.Partial("NameOfThePartial")

Launching a Radwindow in IE 6 causes all dropdowns to hide

When launching a modal radwindow in IE 6, any dropdown's visible on the parent page are hidden. Once they are hidden, they are gone even after the modal has been closed. These are pure ASP.NET dropdownlists. There is nothing special about the dropdown's that are hidden - I can add new dropdowns to the page with nothing in them, and they still go away on launch. Any ideas out there?
I am using ASP.NET 3.5, 2009 Q3 of Telerik's ASP.NET AJAX Controls, testing with IE 6 (6.0.2600) on a virtual machine running Windows 2000.
While the issue was initially encountered on a much more complex page, I have created a brand new page, no css, just bare-bones elements, and it still happens in IE 6.
<%# Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits=".WebForm1" %>
<%# Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<telerik:RadScriptManager ID="manager1" runat="server">
</telerik:RadScriptManager>
<asp:DropDownList ID="ddl1" runat="server">
<asp:ListItem Value="1">Item 1</asp:ListItem>
<asp:ListItem Value="2">Item 2</asp:ListItem>
<asp:ListItem Value="3">Item 2</asp:ListItem>
</asp:DropDownList>
<asp:Button ID="btn1" runat="server" OnClientClick="ShowModal(); return false;" Text="click" />
</div>
<telerik:RadWindowManager ID="RadWindowManager1" runat="server" />
<telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
<script type="text/javascript">
function ShowModal() {
var wnd = radopen('<%=ResolveUrl("~/register.aspx") %>', null);
wnd.set_modal(true);
wnd.center();
wnd.set_behaviors(Telerik.Web.UI.WindowBehaviors.Close + Telerik.Web.UI.WindowBehaviors.Move + Telerik.Web.UI.WindowBehaviors.Resize);
wnd.show();
return false;
}
</script>
</telerik:RadScriptBlock>
</form>
</body>
</html>
It appears that when showing the radwindow with modal being set to true, the dropdown's visibility attribute is being set to hidden. With modal being set to false, the dropdown is fine...
Thanks
Dan Appleyard
We've talked in Telerik's forum and I just wanted to add the info here as it could be of help for other users:
The problem here is with the logic. With your code you do the following:
open the RadWindow control
set its modal property to true. In this case we are hiding the dropdowns in IE6.
set the behaviors of the control
center the window (I assume you do this to redraw the window after setting its behaviors).
You call the show() method again. Because you are calling show() for a window that is modal, the code that hides the dropdowns is run again - that is the reason for them not being visible after the window is closed.
To avoid the problem, I suggest not to call show() again, but to call the center() method last.
RadWindow explicitly hides the dropdowns in IE6 because prior to IE7, dropdowns and list items were heavyweight objects that were rendered above all DHTML elements on the page, including the modal background of RadWindow. This made possible for users to still use the dropdowns on the parent page even if a modal RadWindow was shown.
To avoid that we disable the dropdowns if the browser is IE7+ and hide them completely if it is IE6.
What version of ASP.NET are you running, and what version of Teleriks Rad Window? I have had a lot of issues with older versions, but their new versions seem to be working great.
I'd test it out on a separate page.
Create a new page with a few DDL's randomly filled
Add a basic rad window control to it - and hook it up so it can be invoked
See if you can recreate the issue. If you can't, then it's most likely something with CSS, JavaScript or the HTML markup.
Edit:
Also remember IE6 has drop down issues. Usually the main issue is the dropdown list is always above every other control, but I wouldn't hold my breath if it's something browser related.

Resources