Passing data to nested master pages in MVC2 through ViewData - asp.net-mvc-2

I've been trying to figure out a way to pass data to a nested master page. I'm using a nested master page because it allows me a secondary layer of navigation on my website, which can then be extended by other views which need that secondary layer of navigation.
For some reason I'm unable to access ViewData["field"]. Compiler throws the error that ViewData is not in the context of the nested master page. And I also can't use child actions, they too do not exist in the context of the nested master page.
This is how the nested master page has been declared:
<%# Master Language="C#" MasterPageFile="~/Views/Shared/Site.Master" AutoEventWireup="true" CodeBehind="Curator.master.cs" Inherits="Atlasweb.Views.Shared.Curator" %>
I've tried changing the "Inherits" attribute to System.Web.Mvc.ViewMasterPage to see if it would allow me to access ViewData or child actions, but no luck.

The official way has been outlined by MSDN here.
Below is how I addressed my own error if it relates to you as well.
So this is what I figured out: Originally, when I added a new item, I selected "Nested Master Page". This construct might be older than MVC2, because MVC2 allows me to create a "MasterPage" and then add the attribute MasterPageFile which I can point to a [parent] master page to create nesting. Seems to work for me.
<%# Master Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewMasterPage" %>

Related

Directing via an Action to the same JSP page currently loaded, reloading the user's input Data Struts 2

I currently have a JSP Page with a form in it.
On submission of this form I want to reload this same page with the form being populated with the user input values before the form was submitted.
The Search results will then be outputted on the page.
I have successfully got the search results to output on the page but would like some advice on how to keep the input values in the form elements on page reload.
I did load the search results via the struts 2 Ajax library however if there was a validation error the ajax request would return the full jsp page itself, rather than the search results, as on error the page should reload itself displaying the action errors. As a result I have abandoned using Ajax for loading the search results.
#1: Classic way
If you send a form from search.jsp to search.action , and on SUCCESS you will load the result in searchResult.jsp, and searchResult.jsp contains the same form with the search criteria (and obviously the grid with the search results), in order to preserve and automatically re-populate the criteria you've written in the previous page, you need:
the same Struts2 tags with the same name/value attribute in both search.jsp and searchResult.jsp; actually, I suggest you to create a JSP snippet and to include it in both the JSPs with <jsp:include/>, to avoid code redundancy (two identical forms in two different pages);
the Getters and Setters for all the variables in your search.action, to be set by search.jsp, and to be read by searchResult.jsp.
No AJAX is involved in this, and as said by Dave, it's trivial.
#2: AJAX way
If you instead are using AJAX, then your form will be posted but your page will remain the same, only a target div (the div containing the results of the search) will be populated.
In this case, the data will be preserved because the page will not be reloaded.
Theoretically, in your searchAJAX.action you would only need the Setters for the search criteria, because they will only need to be set, and not read back.
Being your SUCCESS result loaded in a div, by the way, will result in the need of loading a JSP snippet, not a whole JSP. The JSP snippet returned will be injected into the body of the original page, then it should contain only the relevant HTML (and the struts-tags definition), without DTD, <html>, <head> nor <body> elements.
This is valid for the SUCCESS, but for the ERROR result too.
If you return a whole JSP page as global error, or action local error result, you will have a page inside a page, as you had.
The solution is to use
a full JSP as error page for ERROR result returned by classic Actions;
a JSP snippet as error page for ERROR result returned by AJAX Actions.
an example of a JSP snippet for ERROR:
<%# page contentType="text/html; charset=UTF-8" %>
<%# taglib prefix="s" uri="/struts-tags" %>
<strong>OOOOPS an error occurred !</strong>
Obviously another way would be returning a JSON array of data, parsing it and building the HTML client-side with Javascript, to reduce the load of network traffic, but you can easily start with the old way.

load data and navigate using the same action

I'm newbie with zk6 framework. I created a view model class where i'm trying to navigate from one zul and load some data in another one:
public class SearchVM {
#Command
#NotifyChange({ "searchBean","slides" })
public void doSearch() {
//load data (slides) from data base
//navigate to another zul where i display my data
}
}
The data is displayed if i stay in the same zul but i get nothing if i navigate to another one.
i tried to use Executions.sendRedirect("/result.zul") with no sucess.
Don't do a browser redirect. Show the results using AJAX.
So in the following a single zul file has two zones, once is hidden by default. When you click the button it hides the first zone and shows the second.
<zk>
<zscript>
boolean showFirstZone = true;
</zscript>
<window visible="${showFirstZone}" id="firstZoneWindow">
This is first zone.
<include src="/WEB-INF/search/search-input.zul"/>
<button label="Switch To Results" onClick="secondZoneWindow.visible=true;firstZoneWindow.visible=false;" />
</window>
<window visible="${!showFirstZone}" id="secondZoneWindow" >
This is second zone.
<include src="/WEB-INF/search/search-result.zul"/>
</window>
</zk>
Notice that I put the included zul files under /WEB-INF so that they are not accessible from the browser which is a good idea. That way only the entry pages which define the desktops of the system are in the main folder of the site (e.g. one for customers, one for staff, one for admins) each of which can reuse the including fragments hidden under /WEB-INF.
The Theory:
With php/jsp you have the browser request new pages and you draw them so that they see related dated via the session. ZK is a desktop oriented framework where you tend to build "single page applications" which means applications updated by AJAX. Doing a browser redirect is not doing an AJAX update. Your forcing a refetch of all the JS and CSS and re-evaluation of the zul file which is a lot less efficient than doing a dynamic update over AJAX.
If you read http://books.zkoss.org/wiki/ZK%20Developer%27s%20Reference/UI%20Composing/Component-based%20UI it indicates that when you open a new URL you are creating a new desktop. ZK actually puts in a body onunload javascript handler onto the html page it renders telling the browser to send a final AJAX event to destroy the existing desktop when the user navigates to a new url. So your actually destroying your ViewModel when you have your user navigate away from your first zul page. That's why you don't see any data at the new url the browser goes to; it is an entirely new desktop which would get an entirely new ViewModel which has nothing to do with the one the user went away from.

Compile Web User Control to Custom Control namespace name could not be found?

Example aspx code:
my sample code
<%# Register TagPrefix="XF" Namespace="MyNameSPace" %>
i want to register the tag in my controls, but why it said the namespace could not be found? any ideal?
You are either missing the assembly attribute or you are trying to register a usercontrol without the src attribute:
Real world working examples from a current project of mine:
A user control (.ascx):
<%# Register TagPrefix="uc1" TagName="FooDialog" Src="FooDialog.ascx" %>
A webcontrol (defined in a class with no designer file):
<%# Register TagPrefix="ie" Namespace="Microsoft.Web.UI.WebControls" Assembly="Microsoft.Web.UI.WebControls" %>

MVC2: Non-view aspx page in iframe

I have a contradiction to deal with:
I need to make a stylesheet load for a reporting object (for ASP.NET -- it requires runat), however, it won't compile when I have <% %> tags in . I need the <% %> stuff in to load stylesheets and jscripts for the rest of the page.
So, I'm going to load the reporting object into an wrapped in a non-view, non-master-bound aspx page -- so I don't need the other CSS stuff (it's in the Site.Master outside of the iframe)... however, I'm getting a 404 when I load /APP/Reports/viewer.aspx... so it seems to be a controller thing.
I tried googling for the answer, but I'm not sure how to ask the question.

change form action from aspx page to master page behind it

i have a master page and a child aspx page, coneected to each other. the master page has the form in it. Now the child page has checkboxes, whose value i would like to pass to another child page with same master page behind it.
Can i change the action=abc.aspx and method=post?
How can i send all the checkbox values (checkbox.text = abc#oke.com) to the next page?
there are lots of these values that need to pass to nex tpage.
Use Button.PostBackUrl to change the page which the button posts to, and then on the target page, use Page.PreviousPage to get a reference to the source page (and therefore its controls).
By default you can use Page.PreviousPage.FindControl(...) to find a control on the source page by ID, then cast it to a checkbox and retrieve its values. You can also specify the type of the previous page with a <%# PreviousPageType %> directive, and then access the previous page's public properties.
See Cross-Page Posting for details.