ViewData["Title"] is accessible only the current view? or it is possible to access other views also?
View Complete Post
I'm building a user registration wizard with ASP.NET. I'm redirecting the user to a different view for each step of the wizard. Initially, I was using TempData to store values but I realized that a couple of my values will need to persist beyond one request.
So now I'm trying to use ViewData but the behavior is different. When using TempData, I am able to render the view with the data but when I use ViewData, I get "Object reference not set to an instance of an object" when it attempts to render the view.
When I use TempData, it works, but only for the next request (by design from my understanding).
Here is my code. Any ideas on what I'm doing wrong? Also, if anyone has suggestions on to better handle a user registration wizard, I'm all ears. Thanks.
ICompanyInterface service = new CompanyRepository();
bool compWebsite = service.CheckWebsite(model.Website);
if (compWebsite == true)
ViewData["CompanyInfo"] = service.GetCompanyInfo(model.Website);
I have the following code. When the View is rendered, I get "Object reference not set to an instance of an object" on the ViewData["Role"]. Not sure what I'm doing wrong...
public int CheckUserRoles(string Username)
int groupCheck = 1;
using (DirectoryEntry de = new DirectoryEntry())
using (DirectorySearcher adSearch = new DirectorySearcher(de))
StringBuilder groupsList = new StringBuilder();
adSearch.Filter = "(sAMAccountName=" + Username + ")";
SearchResult result = adSearch.FindOne();
if (result != null)
foreach (string item in result.Properties["memberOf"])
var query = from role in db.Roles
where role.Name == item
if (query.Count() > 0)
"When a partial view is instantiated, it gets its own copy of the ViewDataDictionary object that is available to the parent view. The partial view therefore has access to the data of the parent view. However, if the partial view updates the data, those updates affect only the partial view's ViewData object. The parent view's data is not changed.
Is there a common way around this?
For instance I have a View containing two Partial Views (User Controls) that source the same data from the Parents ViewData. The first Partial View is able to update (add/delete) certain data from the Parents View Data, however the second Partial View sources the same data but obviously isn't reflecting the changes owing to the above MSDN statement.
Is it possible to change Properties of ViewData.ModelMetadata in Controller?. For example, can I do the following to change the display information of the LogOnModel:
// URL: /Account/LogOn
public ActionResult LogOn()
ViewData.Model = new LogOnModel();
foreach (var prop in ViewData.ModelMetadata.Properties)
if (prop.PropertyName == "UserName")
prop.DisplayName = "Nombre de Usuario";
if (prop.PropertyName == "Password")
prop.DisplayName = "ContraseÃÂ±a";
if (prop.PropertyName == "RememberMe")
prop.DisplayName = "Recordarme?";
When I do that there is no errors but DisplayName is not change. I'm trying to localize strings to different languages and also to make some attributes of the model different depending on users roles. I've been investigating many ways of doing i
I have the following scenario,
2 custom web control with following details;
Control1 is added to page by registering the control statically using
<%@ Register Assembly="control1" Namespace="control1"
Control1 is available when the page is loaded, when button1 in control1 is clicked, I am dynamically generating the control2 and adding it in a static collection inside OnInit
Event. Static collection is required to preserve the controls on postback. The static collection is then loaded into PlaceHolder control.
When button2 on the control is clicked, I am dynamically generating control1 and adding it to the placeholder as mentioned above.
The drop down values in the custom control added statically on the page by registering the controls preserves the data on post back. The dynamically added controls do not preserve the data on postback.
Any pointers, samples in this regard will be helpful.