In my application I have two Master pages and they are used in various different cases. Say one master view just renders the top half of the page and another master view that renders the top half plus a navigation bar to the side. We pass around data to these Master pages using view models
Now in my controller my index action refers to the MasterPage with the navigation bar and a details tab that does not need the navigation bar. But there is a problem now whenever I try to render the Details page my site crashes at the Site.MasterWithNavigation although it is noway involved with my details view. i have no clue how it lands up there.
On attaching the debugger and checking where the pae is crashing it showed me it is crashing at the Site.MasterWithNavigation and on checking the call stack there was just one entry which took me to my other Site.Master and showed the exception at a random partial view rendering line. I thought just for the heck of it let me comment out that piece of line and again saw the crash occurring now at a different line where I render an HTML input element.
Any idea why the hell I am seeing this? Note we have other pages that use the second master page but for some reason they are all in a different controller called WhateeverDetailsController. Do you think there is a problem when we use two different master pages across two different actions within the same controller.
I am not sure why you are using multile master pages together but I use one master page only, and expose relevant tags to all pages such as:
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Title
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ScriptContentHolder" runat="server">
<%= Html.Script("jquery-1.4.4.min.js")%>
<%= Html.Script("jquery-ui-1.8.7.min.js")%>
<%= Html.Script("MicrosoftAjax.js")%>
<%= Html.Script("MicrosoftMvcAjax.js")%>
<%= Html.Script("MicrosoftMvcValidation.js")%>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MenuContent" runat="server">
<% Html.RenderPartial("IManagerLinks"); %>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="MainContent" runat="server">
<div id="leftContent50">
<h4>add a new comment</h4>
<% Html.RenderPartial("AddCommentUC", Model.AddComment); %>
</div>
<div id="rightContent50">
something else here
</div>
<br style="clear: both;" />
</asp:Content>
You could very easily do the same for the top part of your page, side part and title and use css to style everything up.
Related
I am building asp.net web form. in some of my pages i added juice tag control to organized collection data for Related use-cases.
For some reason unknown to me, when i switch my code from source view to design view, i can't see all the Text boxes. But when i view it in the browser i see the text box and the button. Because of this i cannot access value of my text box from code behind. Can some one tell me the cause of this and how i can get the values of my text box from code behind.
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<div>
<juice:tabs id="_Default" runat="server">
<Juice:TabPage Title="Personaldata" ID="_Tab1">
<TabContent>
<label>FirstName</label>
<asp:TextBox ID="txtfirstname" runat="server"></asp:TextBox>
</TabContent>
</Juice:TabPage>
</div>
</asp:Content>
I try accessing my text box value as follows:
string firstname = txtfirstname.Text.Tostring();
But the text value is not recognized from code behind.
I am developing a web app using asp.net mvc 3. I have a main layout page which contains jquery ui tabs.
I am using knockout.js binding tool. My issue is from my tabs how can I go the relevant controller to return the view. Example is I click on tasks project so in the container for the view it should show the tasks page as rendered by the tasks controller
Any help would be good
Thanks
The simplest solution is to us RenderPartial. Then you can either bind each tab via knockout, or bind the whole lot of them.
<div id="tabs">
<ul>
<li>Nunc tincidunt</li>
<li>Proin dolor</li>
<li>Aenean lacinia</li>
</ul>
<div id="tabs-1">
<% Html.RenderPartial("TabOne", Model);%>
</div>
<div id="tabs-2">
<% Html.RenderPartial("TabTwo", Model);%>
</div>
<div id="tabs-3">
<% Html.RenderPartial("TabThree", Model);%>
</div>
This assumes that the html content doesn't vary based off of the data, or at least not so much that knockout can't take care of it. If your html varies a lot you can use a routing system like Crossroads.js (http://millermedeiros.github.com/crossroads.js/) and fetch the data for the div using ajax.
By definition I had to post this question. I received the error on this line using ASP.NET MVC 3 and ASPX form. Where's my typo?
<a href="<%= Html.Action("About", "Home") %>">
<img src="<%= Url.Content("~/Content/images/newfront_04.jpg") %>" /></a>
I created a blank project to compare:
Web Config is identical minus connection strings (including Views web.config)
Global.asax.cs including routes is identical minus namespace
Page directive is identical
Home Controller code is identical minus namespace
Taking this line out makes everything work
The entire page is html with the exception of the page directive and ContentPlaceHolders
This is the Site.Master file
Html.Action is actually rendering that action where you are putting that code, and it's causing reentrancy there. That is: it's calling the whole action and outputting the resulting view... not outputting the url.
What you probably wanted was Html.ActionLink (which renders the whole A tag for you), instead, or Url.Action, to just output the URL - rather than the action result again.
Try Url.Action instead of Html.Action
<a href="<%= Url.Action("About", "Home") %>">
<img src="<%= Url.Content("~/Content/images/newfront_04.jpg") %>" /></a>
I'm trying to wrap content with some static HTML in MVC and I'm not having any luck figuring this out. There must be an obvious solution that I'm not seeing, as this would seem like a desired feature.
In my View, I need to wrap HTML content with something:
<uc1:mc>
<p>Hello World!</p>
</uc1:mc>
That will render like:
<div class="ribbon">
<div class="left"></div>
<p>Hello World!</p>
<div class="right"></div>
</div>
With a Template like:
<div class="ribbon">
<div class="left"></div>
<%= IncomingMarkupGoesHere %>
<div class="right"></div>
</div>
The idea is to reuse html that wraps around other html.
I'm currently using two User Controls to achieve this, one with everything before and the other with everything after. Something like this:
<% Html.RenderPartial("RightRibbon_Start"); %>
Target Content...
<% Html.RenderPartial("RightRibbon_End"); %>
But this seems sloppy and isn't conducive to passing parameters that apply to HTML before and after the target content.
It's important that the content to be wrapped be allow to be written as multiple lined markup and not just a string, otherwise I would just pass the content as the Model.
What about creating helpers and passing the HTML in as an argument?
Passing html markup into an ASP.NET User Control
My friend I are collaborating on a project, he's going to create the Master Page and I'll create the forms.
How can I assign a master page to my existent .aspx form?
I believe the only thing you need to do is have MasterPageFile in your page declaration, like so:
<%# Page Language="C#" AutoEventWireup="true" MasterPageFile="~/MasterPage.master"
CodeFile="ContentPage.aspx.cs" Inherits="ContentPages_ContentPage" %>
And, of course, make sure you use the <asp:Content> tags to design your page.
<asp:Content ID="mainContent" runat=server ContentPlaceholderID=ContentPlaceholder1>