MVC :: Viewdata Is Defiant Null Always?
Apr 15, 2010i 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]....
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]....
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?
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]...
<%#ViewData["id"] %>
<h2>MarkerDetail</h2>
<script language="javascript" type="text/javascript">
$(document).ready(function(){
$.ajax({
url:"/Marker/MarkerDetailPartial",
data:"",
success:function(result){
$("#ReplyDetails").html(result);
},
error:function(result){
}
});
});
</script>
<div id="ReplyDetails">
</div>
& i want to send Id only By this Ajax
I have a little MVC 3 challenge that I am trying to overcome.Here is my scenario:I have a controller called PersonController.cs with 5 methods:Add Add (post) Edit Edit (post) PopulateName(string EmailAddress) - POST
I have a viewdata class called PersonViewData.cs with 3 pieces of data:
Email FirstName LastName
I have 2 PageViews (Edit.aspx and Add.aspx)I have 1 PartialView (Details.ascx) - with 3 textboxes (Name, Email, Phone)I want to reuse this partial view in both the Edit.aspx and Add.aspx Views.
The user should NOT enter the First Name/Last Name - rather, once the user has entered the email address (OnChange of Email textbox), the First Name/ Last Name of person should be populated. This is done using the PopulateName(string EmailAddress) controller method. Meaning, I have an AJAX Form inside the partial view
Then once all 3 fields are populated. The user should be able to submit either the Add or Edit HtmlForm.
Code of Edit.aspx:
[Code]....
Code of Add.aspx:
[Code]....
The main issue is as follows:I have an AJAX Form inside the partial view. Since now we have a PageView Form and nested PartialView AjaxForm - Form within a Form - the Browser has a hard time with this concept. In fact, when a person enters an email address, the frmEdit/frmAdd gets submitted.
i need to show project information by value of dropdownlist.by using this code i get a list of data to drop down list.now how can i access the first data in ViewData(or record)
[Code]....
Does anyone have any idea why the code below doesn't give me any value but instead gives me "System.Web.Mvc.SelectListItem"? If I don't do a foreach but instead substitute the ViewData with this
<%= Html.DropDownList("PersonOnCallCheckBoxList") %>, I get the correct value.
foreach (var person in ViewData["Person"] as IEnumerable)
{
%>
<input type="checkbox" value="<%= person %>" /><%= person %><br />
<%
}
I'm new to .Net development, and now are following NerdDinner tutorial. Just wondering if any of you would be able to tell me What is the differences between ViewData and ViewModel(all I know is they are used to pass some form of data from controller to view) and perhaps tell me on what situation should I use ViewData instead of ViewModel and vice versa
View 1 RepliesI have one ActionResult method
[Code]....
This ActionResult is executed multiple time accoording the number user selected from previous page..each and every student id and StudentType is passed by that view to this ActionResult. my question is there any way that in ViewData we can store all these id's and studentType's so that I can use these id' and StudentType's in other ActionResult? bec I need only these two things in other ActionResult? I can implement this using cache but I dont want to do with that.
I have the following code in my post action method for Edit.
JobCardService.Update(viewData.JobCard);
var js = new JavaScriptSerializer();
ViewData["Notifications"] = js.Serialize(new {NoteificationType = "Success", Message = "The installtion was successfully updated"});
return RedirectToAction("Index");
However, on the client, ViewData is null/empty, i.e. this client code
var notifications = eval("<%= ViewData["Notifications"]%>");
renders as
var notifications = eval("");
I'm sure I'm doing something small wrong.
tempdata variables works like a session variables?
basically i want to do is to when the form loads for the first time the variables should be empty. but the variable should be persisted until i am on that form.
the form contains searching with a submit button as well as the paging . basically my ques is to use what approach should i use?
My doubt is i have two tables with Id as (Primary key) in one table and in the next table i have a Category Id field as Foreign key relationship with the 1st tabl Id field...
I have created a create view for the 1st table.My question is i have created a partial view for the 2nd table,but i need to pass the Id value to the second tables category Id field...So is there any way to do it by using Viewdata?
I am passing certain string value to a view using "ViewData" and I need to print the contents on a window which is rendered using Javascript. My question is how to pass this value to a window which is rendered using Window.Open ?
View 16 RepliesThe functionality I'm looking for is really simple. I'd like to increment a an integer called
index. Each time I click a button, I post a form to an action method, which increment index and redisplay the view with the new value of the index.
So, I've 2 action methods called Increment (Get and Post versions ):
Increment (GET) action method displays the View, supplying also an initial value of index through the ViewData.
[Code]....
When I click to the button "increment" on the view, I post a form to Increment (POST). The value from the ViewData is sent back to the Controller through an "Hidden field" [Code].... Increment (POST) action method pulls the the value of the index, increments the value, and sends back the new value of index through ViewData when it re-displays the view.[Code]....
Unfortunately, all I can get is ONE increment. in the case above, I get 2. after that, I keep getting 2. If I change the value to 2, I get 3 and nothing else, etc... I suspect that ViewData, once it has gotten a value, keeps it forever.
I would like to know the limit of viewdata items.
I mean how many (no. of records) can be stored in one viewdata instance.
I am new to MVC3 razor and facing one issue as described below. I have one strongly typed view to display list of items and user can edit the view. When user click on a print button a popup should open to print the list . So I have to pass the current view to the popup page.
We can pass a single value as like to popup screen as "window.open('@Url.Action("ViewName", "ContollerName",new {id="ParameterValue"})'.
Is it possible to pass the current view to to popup window as a parameter like new {id="Parameter"}) ?
I've run into a wall with the ViewData construct, but not sure exactly where the limitation lies or the best way to get around it. I have a complicated View that needs to contain many dropdown listboxes. I am loading up ViewData objects in the controller for the view. Apparently, I have hit some limit and cannot add another ViewData object for another dropdown. I'm not sure if the limit is the number of distinct objects in ViewData, the amount of memory in my test server, or the overall amount of data I am trying to load into the ViewData collection.
View 7 RepliesI saw the ViewBag in MVC3? How's that different than Viewdata in MVC2?
View 2 Replies[Code]....
.aspx View:
[Code]....
How to bind a dataSource property of the grid to ViewData["Data Source"]?
i am using this code that returns data form 3 tables
[Code]....
and i have a PartialView that will show the data.so how can i show the data in a foreach on my PartialView
I have a View loading a PartialView via jQuery. The PartialView has ViewData that the jQuery needs to access, but I can't seem to get to it from the jQuery. The code below uses the HighChart jQuery plugin (and it is just test code taken from the HighChart example page):
<script type="text/javascript">
var chart1; // globally available [Code]....
This jQuery is in the main view, because I don't know how I could put it in the PartialView with the document ready function. But by putting the call to the HighChart function in the callback of the get() function it works in the partial view. But accessing the ViewData doesn't...
How can I achieve this? I need to get the data from the PartialView action method in order to populate the HighChart data...
I have an several controllers where I want every ActionResult to return the same viewdata. In this case, I know I will always need basic product and employee information.
Right now I've been doing something like this:
[code]....
This is just pseudo-code so forgive any obvious errors, is there a better way to be doing this? I thought of having my controller inherit a class that pretty much does the same thing you see here, but I didn't see any great advantages to that. It feels like what I'm doing is wrong and unmaintable, what's the best way to go about this?
Have seen in the MusicStore PDF witch can be sownloaded from [URL], That is it possible to render additional vew data. so: I have my ViewDataModel
[Code]....
I have the Model:
[Code]....
In my controller, I add the data into the model:
[Code]....
And I try to render it with Html.EditorFor.
[Code]....
My problem is here, that it only render Keyword
Is there any simple method to pass viewdata to masterpage. For example, I create a viewdata["test"] in the testing controller. I pass it to masterpage so the masterpage can show this value.Is there any simple method to do it? Can I use session to do it and how?
View 6 RepliesI'm trying to do:
[Code]....
But each time I do this, the ViewData object seems to disappear (intellisense doesn't show it). Also, Model goes away too. I must be making a really simple/dumb mistake. I also tried to Import the namespace containing the CompanyModel class on the same aspx, but that doesn't do anything.
When I try to view the page in the browser I get this error:
Parser Error Message: Could not load type 'System.Web.Mvc.ViewPage<CompanyModel>'.