C# - ViewData Set In An ActionFilter Is Coming Out Null On Master Page MVC3?
Feb 15, 2011
My Original Issue here:Help! I've got repository access in my MVC master page! Refactor time!What originated as a re factoring job to improve performance has revealed new issues. If I should keep this in my original question - feel free to delete this one, and rename the old one to something more relevant. I'm using an ActionFilter applied to a base controller to load some user-customized settings. My issue is that I save these settings in the filterContext.Controller.ViewData object but its coming through as null on my master page. Here is the relevant code:
Action Filter
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
public class StoreSettingsActionFilter : ActionFilterAttribute
[code]...
View 1 Replies
Similar Messages:
Jan 12, 2011
We are trying to fill JqGrid in ASP.NET MVC3 application where datatype is set to 'jsonstring' and in it's action controller, we set the json data string in ViewData and retrieve the same in javascript function where we used it to fill the Jqgrid.
// Action code
[Code]....
// Javascript code to fill Jqgrid
[Code]....
[Code]....
There is an error while filling grid and when i alert the data it shows " in place of " in data, as below.
{{"total":2,"page":1,"records":2,"rows":[{"RequestID":"1","cell":["CPU","DELL OptiPlex 745","DELL","OptiPlex 745","5"]},{"RequestID":"2","cell":["CPU","TOSHIBA Tablet Portege 3500","TOSHIBA","Tablet Portege 3500","10"]}]}
[data displays fine on this post :) ]
The decodeURI function do not work on strData and it always show " in place of " in the data. We do not want to replace the " with " in a loop as it slow the page with large data.
View 2 Replies
Dec 21, 2010
I have a nested master page with radio button controls and one or two dropdowns (depending on the radio button chosen). The dropdown(s) contains either carriers or our customers. If the dropdown type is customer, we display another dropdown to determine what type of customer (current, former, or test). Once a carrier or customer is chosen, an action is called to "set" the customer information in the session. This all works great. The problem is trying to persist the dropdown type, customer type, and customer or carrier chosen over each action/view. Once a customer or carrier is set, the user can chose different menu options (also on the master page) to perform different tasks against the customer or carrier data. I am still fairly new to asp.net mvc and to jquery and ajax. I have racked my brain and tried several different scenarios to get this to work. I tried a master view model which got inherited by the other view models. I couldn't get that to work. Now I am trying a base controller and just setting things in viewdata, but I still can't get it to work once I move to next controller/action/view. Can someone please let me know the best practice for doing this? And or tell me where I'm going wrong? I am at a pretty critical point in this project and am running out of time. The code follows:
Global.asax:
[Code]....
Site.Master:
[Code]....
View 4 Replies
Nov 23, 2010
im getting the following exception for use into a master page the helper html.renderpartial(). This works on mvc views that uses this master page, but im trying to execute an old aspx webform page that uses the same masterpage. And here comes following exception:A ViewMasterPage can be used only with content pages that derive from ViewPage or ViewPage.This is the code of my master page:
<body>
<%Html.RenderPartial("PartialView"); %>
<div style="background-color:Aqua;">
<asp:ContentPlaceHolder ID="MainContent" runat="server">
</asp:ContentPlaceHolder>
</div>
</body>
I would like to render some partialviews on my master page. Is it possible?
View 1 Replies
Sep 21, 2012
I'm using this wdCalendar code I found to add a Google calendar like calendar to my application. It uses mostly JQuery to work. Anyways, I notice when I use a pull down menu from the master page, the content page is blocking it (see attached image).
View 1 Replies
Apr 15, 2010
i return data to view by viewdata. and allways checking the viewdata for null but the viewdata is defiant null
this is my code for return data from database
[Code]....
View 1 Replies
Jan 19, 2010
My controller calls a class in my model which is getting data from a REST web service. The class in the model then passes the data back to the controller using an IList, like so:
[Code]....
My problem is this: The data that is held in the IList isn't there until the user has done a search in the View, submiting a form. This is a basic search function with 2 textboxes and a submit button in a form. When the user clicks submit, the controller action is called, the web service is then called, and the data in the IList gets populated. The problem is that in the View I am using a strongly typed view and my model reference in the foreach loop throws a Null Reference Exception because there is no data in it, because a search has not been conducted yet...
[Code]....
So, how can I have the above foreach loop in my view if there isn't any data in the model until a search has been conducted? Is there a better way that I should be doing this?
Essentially, what's the best method for passing data back to a view that is based on a form submittion?
View 6 Replies
Jul 8, 2010
I have a simple ViewModel with 3 properties...I have some javascript going on where if a link is clicked, JQuery sets the values for 2 textfields (1 hidden) and a submit button where i process the rest of the Model on [HttpPost] - but for some reason some fields (the ones NOT set by javascript/JQuery) are coming back null - while on the page there is clearly values in them
[Code]....
And my Controller has the HttpGet and HttpPost, and a method that creates the nodes for the JQuery tree.
When you click on a node, this is when some values are set via javascript
[Code]....
View 4 Replies
Oct 25, 2010
I am using a CustomValidator in ASP.NET as follows:
<asp:CustomValidator ID="cvComment" ControlToValidate="txtComment" Display="None"
EnableClientScript="true" ClientValidationFunction="validateComment"
runat="server" ></asp:CustomValidator>
And this is the function that gets called:
function validateComment(source, args) {
var reComment = new RegExp("^[a-zA-Z0-9',!;?@#%*.s]{1,1000}$");
var validComment = reComment.test(window.event.srcElement.value);
if (!validComment)
alert("The comment has illegal characters");
args.IsValid = validComment;
}
Upon clicking the button that triggers the validator, the application breaks and I can see that the window.event property is null, so obviously there's a null reference trying to match the regEx. My question is why could the window.event be showing up as null? I could've sworn this was working before.
EDIT:
I have modified the function as such:
var check = document.getElementById(source.id);
var checky = check.attributes["controltovalidate"].value;
var checkyo = document.getElementById(checky);
var validHour = reOutHour.test(checkyo.value);
if (!validHour)
alert("The time is incorrectly formatted");
args.IsValid = validHour;
Now this is working on Internet Explorer, but not on Firefox...
View 1 Replies
Jun 29, 2010
I created a base Controller for the other Controllers to derrive from, and in that controller I overrode the OnActionExecuting method so that each time any Controller executes a method, I can run some code. In that code I added a value to ViewData, and in the Master View I want to either display certain items or not based on the value of the ViewData item set. The problem is, once I get to the Master View, the ViewData doesn't have anything in it. I am not sure what I'm doing wrong.
View 1 Replies
Apr 6, 2010
Have created a Webform based on a master page.The code executes OK and sends data to the database, but inserts null values for all entries except the GetDate.
If I use exactly the same code in a new webform which isn't based on the master page, it inserts everything correctly.Here is a snippet from the form which uses the master page: -
<%@ Page Title="" Language="C#" MasterPageFile="~/SpeedDateMasterPage.master" %>
<script runat="server">
private void AddToDatabase(object source, EventArgs e) [code].....
View 10 Replies
Jun 10, 2010
Im trying to use code provide in this link below.http://www.codeproject.com/KB/aspnet/MultipleTabWindows.aspxim trying to have the below code in my master page instead of adding to each page. it works if i add to each page, but when i add to ,master page the session value for "WindowName" is always null.how can i fix this?
<script language="javascript" type="text/javascript">if(window.name != "<%=GetWindowName()%>"){ window.name = "invalidAccess"; window.open("InvalidAccess.aspx", "_self");}</script>public string GetWindowName(){ return Session["WindowName"].ToString();}
View 6 Replies
Mar 10, 2010
I've got a master page where I've created two content place holders ('menu content place holder' and 'main body content place holder'). I've placed several controls (drop down lists and a calendar) in one of these content place holders (the 'menu content place holder'). In my content page I've set the 'menu content place holder' to 'Default to Master page content'. In my 'main body content place holder' I've included several controls (table, labels) which depend on the user selected items in the 'menu content place holder'.
After including a reference in all the necessary places- like this:
DropDownList ddlList1 = Master.FindControl("ddlList1")
as
DropDownList;
I still get the following exception (this exception occurs in my content page):
An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details:System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
[Code]....
View 8 Replies
Dec 24, 2010
I have a page in which I am not using cache by using this code:
HttpContext.Current.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
HttpContext.Current.Response.Cache.SetValidUntilExpires(false);
HttpContext.Current.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
HttpContext.Current.Response.Cache.SetNoStore();
Now I want to know: Is there any difference between coming to this page using a proper link or coming back using browser back button, or is there any way to detect this?
View 2 Replies
Mar 7, 2011
I am using ASP button its working properly at client side but on server side its not firing.
<div style="text-align: center">
<div>
<div id="UserName">
<b>LoginName</b>
<asp:TextBox ID="txt_LoginName" runat="server"></asp:TextBox>
</div>
</div>
<div>
<div id="Password">
<b>Password </b>
<asp:TextBox ID="txt_Password" TextMode="Password" runat="server"></asp:TextBox>
</div>
</div>
<div style="text-align: right; width: 210px;">
<asp:Button ID="btn_SignIn" OnClientClick="LogInUser()" UseSubmitBehavior="false" runat="server" Text="Login`enter code here`" />
<asp:Label ID="lbl_InValidError" runat="server"></asp:Label>
</div>
</div>
Client Side Code:
function LogInUser()
{
var LoginName = document.getElementById("<%=txt_LoginName.ClientId %>").value;
var Password = document.getElementById("<%=txt_Password.ClientId%>").value;
[Code]....
View 1 Replies
Feb 1, 2011
I need to build a search page and a results page for an MVC3 app.
View 2 Replies
Jul 7, 2010
I'm doing kind of wizard application that captures information on Contacts. The process of collecting information involves 4 pages. On one of the pages, the user is invited to upload is picture. The last page is called "preview before saving" where the user has 2 choices: (i) Go back to previous pages to make corrections or (ii) click save button to save data to DB. To be able to keep the same data all along those steps, I'm using tricks, such as serialization/deserialization, and TempData[]. On the preview page, I'd like to display all the information entered by the user, including the picture he uploaded.
Here's the basic structure of the image tag.
[Code]....
the src attribute takes values such as, src="../../Content/myPicture.gif or
src = "<"%=Url.Action("Action", "Controller", "RouteValue")%>"/>
In my case, None of the above is applicable because the data needed to display the picture are in the model.My object model has 2 properties called ImageData and ImageMimeType.
My question: How to display the image on an ASP.NET MVC page by using data from the ViewData.model [as opposed to getting data from remote location using for instance Url.Action()]
View 12 Replies
Mar 18, 2010
I have two custom ActionFilters on an action. In first of the actionfilters, I have an redirect performed if a condition is not met (classic authorization). And in another I have an redirect performed if another condition is not met (say role checking). But I do not want to continue to the second actionFilter if the first one is not met. How to do this?
View 1 Replies
Dec 9, 2010
I'm trying to display an image from the database depending on the month of the year.
The image is the sites logo and is displayed in the master page.
I cannot get the image to display on any pages except DisplayLogo.aspx and the master page when viewing DisplayLogo.aspx
i've attached all revelant code below:
[Code]....
View 5 Replies
Nov 18, 2010
What is the best way to pass data to the layout page? Each one of my pages has a different model, but I need to pass consistant data to the layout page so I can show the current app they are on and the array of menu options that get passed into a method that builds the menu.
View 2 Replies
Oct 26, 2010
In order to get Database.Open("sdfsdf"); to work in one of my MVC3 .cshtml pages I had to add a using statement at the top of the page.@using WebMatrix.Data.I added it to the Web.Config file under the <pages><namespaces> section and it didn't work.
1. Do .cshtml pages not respect that section in the web.config? If not
2. Do we need to add @using statements in every page? Or is there a better way?
I can't get helpers like @LinkShare.GetHtml and @Gravatar.GetHtml working despite have references to:
System.Web.WebPages
System.Web.Helpers
And adding @using statements.
3. What am I missing in order to get the helpers working in my MVC3 project?
View 3 Replies
Mar 9, 2011
I have an aspx web page that renders correctly. When converted to razor, it does not. Here is a simplified example (stripped of all extraneous stuff).
aspx:
<asp:Content ID="indexContent" ContentPlaceHolderID="ToolContent" runat="server">
<% string test = "<div><b>Tag Test</b></div>"; %>
<h2><%= test %></h2>
</asp:Content>
razor:
@section ToolContent {
@{ string test = "<div><b>Tag Test</b></div>"; }
<h2>@test</h2>
}
The aspx renders as expected. The razor just displays the content of "test" (<div><b>Tag Test</b></div>) in the header tag.
I assume that my understanding of razor is flawed. If someone could enlighten me and/or show me a solution/work around.
View 1 Replies
Feb 17, 2010
Let's say I have two pages on the same ASP.NET C# WebSite:
Page1.aspx does things in the Page_Load event
I navigate to Page2.aspx using the menu
Page2.aspx does some things then Response.Redirect back to Page1.aspx
Page1.aspx cannot do things in Page_Load event this time because it never fires.
I tried to turn off cache declaratively, tried using true for endResponse in my redirect... nothing seems to make a difference.
View 5 Replies
Aug 2, 2010
I have a master page containing a tree and 3 dropdown lists. I am populating a context menu on right click of each node, and when clicked on any item of the context menu, it navigates to required pages.
My problem is after navigating to the required page, the selected values from the drop down lists and the selected node from the tree are getting cleared.
I can set the selected values for the dropdown lists by making some properties in master page.
But how do i maintain the selected node?
In my content page, i have got the valuepath of the right clicked node.
Or is there any other way than setting the properties in master page?
View 6 Replies
Dec 17, 2010
I am using Actionfilter to globally filter our HTML comments from all action methods and in all controllers. It simply overrides OnActionExecuting and runs the response through a regex to filter the comments. I am also using RenderAction to render some more complicated widgets in my website. There is no caching in place, I just use Renderactionto keep my code as simple possible.
When calling RenderAction from within a Razor View, I get an error message telling me that "Filtering is not allowed". The problem does not occur when calling RenderAction from within an aspx View. It only occurs when calling RenderAction from within a Razor View. In case it matters: the view being rendered is implemented with ASPX. Is this a bug or a known limitation?
View 6 Replies