MVC :: Is It Possible To Change Properties Of ViewData.ModelMetadata In Controller

Nov 29, 2010

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:

[Code]....

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.

View 7 Replies


Similar Messages:

MVC :: Sending Viewdata To Another Controller?

Mar 18, 2011

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"}) ?

View 5 Replies

MVC :: Binding Controller & View Without ViewData?

Feb 13, 2010

I like ASP.NET MVC, because I like to have direct access to my web site's structure. However there's 1 thing that I don't like.

In Ruby on Rails to send data from Controller to View is really easy:

# Get a user in controller

@user = User.first(:id => 1)

# Display him in a view

<%= @user.id %>

In ASP.NET MVC it's much harder

// Controller
User user = new User(1);
ViewData["user"] = user;
// View
<% User user = (MyNamespace.User)ViewData["user"]; %>
<%= user.Id %>

With this ViewData thing all benefits of static languages go away, and we waste time boxing/unboxing objects.

P.S. Don't tell me to use Model object, because this is also true for other variables like integer.

And another question:

I'm trying to implement a comfrtable access to data. Since I can't use LINQ to SQL as I use Postrgresql, I have to do it on my own. I'm tired of direct SQL queries, so I'm trying to implement something like this:

User user = User.Find("first_name" => "Bob");

View 4 Replies

Avoiding The Use Of The Viewdata Enumerable Object In Controller?

Mar 23, 2011

I have 2 points for today I. I have a controller in which i have a public static method for getting the details for a checkbox like

[code]....

is it ok for me to use this same function like this one in the view, so that I do not need to use the viewdata object,

<%: Html.DropDownList("country", new SelectList(UserController.GetCountryLists(), "value", "countryname", "0"))%>

Also i have another query, when i use the same id & name for the radiobuttons, validation at the client side is working fine.If I use the same condition for a group of checkboxes, i get do not get the checkboxes highlighted during client validation and only during server validation, i get the error message, but the controls [checkboxes] do not have a red border indicating the error.I have used my own html helper to generate the checkboxlist as per [URL].

View 1 Replies

MVC :: Pass Message From Controller To View Using Viewdata

Feb 13, 2011

I want to pass a message from the controller to a view using Viewdata. Here is my code:

public ActionResult Create(FormCollection createPage)
{
try
{
......................
ViewData["Message"] = "Success - rec added!!!!" ;
return RedirectToAction("Index");
}
catch (Exception e)
{
ViewData["Message"] = "Exception: " + e.ToString();
return RedirectToAction("Index");
}

On my View I have:

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>::><%: ViewData["Message"] %><::</h2>
<h3>==><%= ViewData["Message"] %><==</h3>
<p>

This is Index.aspx page in Controller folder

</p>
</asp:Content>

I am getting result with empty ViewData["Message"]

View 4 Replies

MVC :: Display ViewData In Mater Page From Global Controller?

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

Bind Object To The Controller, To Show Some Properties Value?

Feb 17, 2011

I'm a junior ASP.NET developer comes from Java background, so may be my question is strange.

I want to build an ascx (asp control) which accept an object as parameter for example :

1- we have a class called Device ( Contains some properties name, color , Specification (another object))

2- we have a control DeviceItem ( Contains Table to view some of the Device properties value ) and contains a property called Device

if the devices object retrieved from the Database and we have an object called device1 from Type Device

is there a direct way to pass the Device object (device1) to the DeviceItem control, some thing like :

<uc1:DeviceItem ID="DeviceItem1" runat="server" Device="THE_DEVICE_OBJECT"/>

and then bind this object to the controller, to show some properties value?

View 4 Replies

MVC :: Can't Get ModelMetadata When There Is Not Data

Mar 7, 2011

I build a gridview View with a generic model type, because the actual model can be anything.

My model is of type: IModelContainer<IModel>

And the definition of that interface is:

[Code]....

In my grid.cshtml i need to get all the propertynames to use as columnheader, but i do not know them beforehand.

I use the following code :

[Code]....

This works perfectly when there is at least 1 row in the Items list, but how do i get propertynames, when there is no data?

I can get the typeof the actual class implementing the IModel interface via a property on my IModelContainer interface if needed, but i don't know how to go from there.

View 6 Replies

MVC :: Using Index For ModelMetadata.FromStringExpression?

Jun 24, 2010

How do I do 'ModelMetadata.FromLambdaExpression(x => x.Books[0], ViewData)' with FromStringExpression?

I tried 'ModelMetadata.FromStringExpression("Books[0]", ViewData)' but it seems it doesn't understand index notation.

View 7 Replies

MVC :: ModelMetadata Property Name For Complex Type?

Feb 3, 2011

[Code]....

[Code]....

How can i get full name of the property ?

View 7 Replies

MVC 3 HtmlHelper Exception Does Not Recognize ModelMetadata On Inherited Interface

Jan 15, 2011

After upgrading to MVC 3 RTM I get an exception where it previously worked.

Here is the scenario. I have several objects that use the same underlying interfaces IActivity and IOwned.

IActivity implements IOwned (another interface)

[code]....

View 3 Replies

Web Forms :: Can Change The Properties Of A Div In The Code Behind

Dec 7, 2010

I'm struggling once again to get something centered on a page, and fighting with recalcitrant browsers. I can fix the problem for one browser by adding a style. I can fix it for the other browser by NOT adding the style. I can determine which browser I'm using. If I can change the properties of a div in the code behind, I can create a class and apply it to the div as needed. I added an id to the class:

<div id="alignLV2" runat="server">

but in the code behind, alignLV2 doesn't seem to have a class property. Is there a way to add a class or change the style?

View 3 Replies

How To Change Border Properties Of ASCX From Code-behind

Feb 25, 2010

I am building a library of asp.net user controls which I am deriving from a custom UserControlBase class which further derives from actual UserControl class. Hierarchy looks like this :

ASCX -> UserControlBase : UserControl

I have this requirement to put a border around all the ASCX's. So, I thought if I can modify UserControlBase it will apply to all ASCXs. I tried following code in Page_Load of UserCOntrolBase but its not working

Code:

this.Attributes.Add("style", "border-color:#FFFF66;border-width:4px;border-style:Dashed;");

What should I do to make it work?

View 6 Replies

Web Forms :: Notify If Any Change In Folder Properties

Mar 25, 2011

I am saving the file name list in the specified folder into the database. But my code should detect automatically if any new files have been added or any files have been deleted from the folder, then only the changed file names should again saved into db. I am not aware of the features of Folder properties.

View 1 Replies

Can't Change The Column Properties In Table In Database

Dec 18, 2010

When I try to edit the Identity Specification from No to Yes there isn't a way to do so. No drop-down arrow or any way to edit the text. How can I change it so that I can actually change the value to 'Yes'?

View 2 Replies

Change Border Properties Of ASCX From Code Behind?

Feb 25, 2010

I am building a library of asp.net user controls which I am deriving from a custom UserControlBase class which further derives from actual UserControl class. Hierarchy looks like this :

ASCX -> UserControlBase : UserControl

I have this requirement to put a border around all the ASCX's. So, I thought if I can modify UserControlBase it will apply to all ASCXs. I tried following code in Page_Load of UserCOntrolBase but its not working

this.Attributes.Add("style", "border-color:#FFFF66;border-width:4px;border-style:Dashed;");

View 1 Replies

How To Change Public Properties Of User Control

Jan 11, 2011

I have a very simple user control in my web site project which has public property declarations as following

[code].....

When i drag the ascx file to one of my aspx page and when i go to code behind of aspx page i can access the controls properties through intelisense, but when i run the project through visual studio i get error "The name 'uctTest1' does not exist in the current context?

This is the line where Error shows when i run the project uctTest.StartDate = DateTime.Now;

aspx page markup :

[code]....

View 3 Replies

MVC :: Change Properties Of Control On Button Click?

Feb 16, 2011

I am a ASP.Net Web Forms developer and new in MVC. I observed that MVC reccommend not to have code behind file. In Web Forms, we handle events in code behind then change properties of various controls there. How to do the same in MVC? For example, if I have to change back color of a label on click of a button then how to do this in MVC?

View 4 Replies

ADO.NET :: Programmatically Change Membership Profile Properties?

Mar 23, 2011

I am working in a Silverlight 4 + RIA Services application. On the server side I am using Entity Framework and SQL Server. The user authentication is performed in the application using the default ASP.NET Membership Provider.

I am also using some profile properties to store some user preferences. Unfortunately I came across a situation where I have to change one of this properties in all users.

Altought I am using EF to manage data persistence, the ASP Membership provider tables are not in my entities diagram, since everything I must do regarding membership is performed using the objects available on the provider.

So I was thinking to use this objects to change the user prefrences, but my question is about what happens if something fails? Is there any transaction object I could use on the Membership objects to perform an atomic operation?

I know EF supports transactions, but in this case I would have to add the asp.net membership tables to my diagram.. only for that operation.

View 6 Replies

Gridview - Change The Color Properties Vertically?

Mar 19, 2011

I have a dynamic gridview, about 35 rows by 11 columns. When the user hovers over a row, I highlight the row's background in green (with CSS:Hover).

I would like to change the column's background as well, but I don't think I can assign css to a entire column. How can I accomplish this?

View 1 Replies

How To Change Default Controller Actionresult

Jan 8, 2010

By default ASP.NET MVC uses ContentResult for controller method that return result not inherited from actionresult type. That is why if we will return some poco entity it will be only its type name.Could I overload something in controller to make it return jsonresult by default.Example:// return json product representation instead of product typename

public MyController: Controller
{
public Product MyAction()
{
return new Product { Name = "Foo", ID = 1 };
[code]...

View 1 Replies

How To Change Properties Of Class In ObjectDataSource Updating-Event

Aug 9, 2010

I have the following situation:My business class:

public class Foo
{
public String A {get;set;}
public DateTime B {get;set;}
// .. and other properties like
public String Intern {get;set;}
}

I'm binding that Item to a DetailsView in Editmode. (I bind a List containing a single object of Foo, becuase I do recall that I can only bind IEnumerable<> classes to the DetailView)The binding is done via a ObjectDataSource

View 1 Replies

SQL Reporting :: Dynamically Change Left And Top Properties Of Table?

Apr 4, 2010

How can I change Left and Top properties of Table control in a .rdlc file from code behind at Run-Time?

View 2 Replies

Render Text File And Change Object's Properties?

Feb 5, 2011

i want to generate the output of an asp.net page by reading a text file, get the controls out of the text, change te properties of these controls, render it and displaying it.

so for example, the text file may contain:

<head>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<sys:Label ID="Label1" runat="server" Text="empty1"></sys:Label>
<sys:Label ID="Label2" runat="server" Text="empty2"></sys:Label>
</div>
</form>
</body>
</html>

after reading the text, i would like to change the properties of the sys:label controls. After that, the text will be rendered, and displayed.

View 1 Replies

.net - Hit The Controller On Change On Radio Button Using Jquery?

Aug 5, 2010

I have a questions..
when initially page load I have two radio button in the page..

Add
Edit

when I select Add radio button I need to go the controller Action Add

$("#Add").change(function () {

// what should I write here to hit the controller?

});

View 4 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved