MVC :: Restore List Of Custom Objects On Postback?

Oct 21, 2010

I have a model containing a List with custom objects, let's say Customer objects. Like this:

[Code]....

In the View I print out (for simplicity) the name and id of the customer objects on the model. How to restore these values on postback if the method signature looks like this:

[Code]....

Should I use hidden values? This is not possible if the List contains items of interface type, for example List<ICustomer> where ICustomer is an interface. Is there any other way to "save" the values on each postback? For example I may want to view validation error messages when the user submits the form and then the properties of the customer object must still be there..

View 5 Replies


Similar Messages:

Forms Data Controls :: Binding A Repeater To A List Of Objects That Have Child Objects?

Nov 17, 2010

have some Objects, lets say Employee and Role defined as below and I have defined relationships in my database that gives me a list of objects say employees and thanks to my framework each employee object also has a Role object linked via the RoleIDID, UserName, Password, Email, RoleIDRoleID, RoleNameSo in code I can do something like this

Employee emp = dataService_GetEmployeeByID(1);
string RoleName = emp.Role.RoleName;

Now here is my problemI can bind any object in a repeater and it works fine for the first level in my relationship

For instance <%# Eval("UserName") %>

But I need to be able to show the details for my child objects as well (Role) so something like this (which does not work)

<%# Eval("Role.RoleName") %>

View 2 Replies

Forms Data Controls :: Binding An Objects(containing Sub Objects) To A Dropdown List?

Apr 6, 2010

I know how to bind a simple objects to a dropdown list. However I am having problems binding my objects which contains sub objects to the control.i.e. with simple object i just do ddl.DataValueField = "myproperty"
with my objects they contains sub objects which i want to bind. I have tried ddl.DataValueField = "sub-object.myproperty" which doesnt work.

View 2 Replies

Dynamic Data Be Made To Work With Custom Business Objects Rather Than Data Objects?

Feb 24, 2010

I'm working on a project in which we have a database, data layer (entity framework), business layer and web/UI layer.I want to use ASP.NET Dynamic Data for the web layer, but don't want it to access the data layer or database, as I want it to be purely running off business logic, and not directly accessing the data.However, it appears that Dynamic Data only allows Linq-to-SQL or entity framework data sources to be used.Has anyone used it with business-layer objects instead?

View 1 Replies

How To Bind Form Collection Back To Custom Model Object That Uses 2 Custom Objects

Mar 23, 2010

What I'm trying to do is rather basic, but I might have my facts mixed up. I have a details page that has a custom class as it's Model. The custom class uses 2 custom objects with yet another custom object a property of one of the 2. The details page outputs a fair amount of information, but allows the user to post a comment. When the user clicks the post button, the page gets posted to a Details action that looks something like this:

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Details(VideoDetailModel vidAndComment) { ....}
[Code]....

The only fields on the form that is posted are CommentText and VideoId. Here is what the VideoDetailModel looks like.

public class VideoDetailModel
{
public VideoDetailModel()
{
[Code]....
I suppose if I added more form fields for the properties I need, they would get posted, but I only need 1 form entry field for the CommentText. If I could get the same Model objects value that were sent to the page to post with the page, it looks like the solution is rather simple. I think using the RenderPartial in the middle of a form is problematic somehow to how the form gets written in html. I can't really put my finger on why things went bonkers, but if I do my RenderPartials before my form and then begin my form with the text entry field and the hidden VideoId, the default ModelBinder works just fine. I was beginning the form, writing the hidden VideoId, rendering several partial views, create my CommentText field, and then closed the form out. The CommentText field would get bound just fine. The hidden VideoId would not. Maybe I missed a rule somewhere about using RenderPartial.

For completeness, the partial view I was rendering took a Comment object and just wrote out it's CommentText data. Several of these objects would exist for a single Video object. All of this data was in a custom type and passed into the View (the main view) as it's Model. This partial view did not have a form and did not have any data entry fields.

View 2 Replies

How To Add Two Objects In The Same List

Feb 24, 2010

Currently i am having a list like List<Tickets> allTickets.I need to select in the same list some corresponding info about the ticket writer like List<Ticket, aspnet_User>.

View 4 Replies

Creating Custom Objects For Wcf?

Oct 2, 2010

I have an existing web application that uses EF and POCO objects. I want to improve the client experience by exposing some of my objects through WCF(JSON). I have this working fine but where I am unsure is how to handle derived objects(not sure if that is the correct term) or IEnumerable anonymous objects if you will.

Let's say I have 3 tables structured like so:

Templates

ID
Template

Groups

ID
Group

Instances

ID
TemplateID
GroupID

This is obviously a one-to-many type relationship. I have my navigation properties setup correctly and getting strongly typed object properties works great. However, how do I send serialized anonymous type object(s) over the wire. Like an object that sends all instances that are equal to groupid=1 and include the names of the template and the object.Am I missing something or do I have to create another class object for WCF that would look like this:

WCF Object

InstanceID
TemplateID
TemplateName
GroupID
GroupName

I guess I could alter my tables to account for this but that seems wrong too. I know that IEnumerable objects can't be serialized and I know that throw away objects are probably not the way to go either. I want to do this the right way but I am not sure how to go about it.

View 1 Replies

AJAX :: Disposing Drag/drop Objects On Postback?

Mar 31, 2010

I have an UpdatePanel that contains several "items" that are in individual divs that are registered as dragdrop objects. I pass the item ID into the object. Everything appears to be working fine until I delete an item/div. The items appear in the correct divs but the ID's are mismatched as if the delete never happened. I know the dispose method is being called for each object. But I don't know how the deleted item ID is still being passed in a drag/drop object that should be re-initialized on every pageLoad. It's difficult to explain but here is some of the relevant code:

Example of generated initializations on postback:

[Code]....

View 1 Replies

Copy List Of Objects?

Jun 21, 2010

I have a list of objects (List1) and I am trying to make a copy of this list (List2) and then change one of the fields in the new list.I used :

List<MyObj> List2 = new List<MyObj>();
List2.AddRange(List1);
I alos tried:
List<MyObj> List2 = new List<MyObj>(List1);
But regardless of the method, when I do:
foreach (MyObj o in List2)
o.some_field = 2

it not only changes the field in Lis2 but alos in List1. Not sure what I am missing here.

View 3 Replies

$.ajax(..) And Passing Custom Objects By Ref?

Dec 10, 2010

How to use $.ajax(..) JSON to invoke asmx webmethods that have 'by ref arguments' for custom classes/objects? Is it possible?

My c# code -
public class MyCustomClass{ public int MyProperty; MyCustomClass(){}}
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public Method1(ref MyCustomClass MyCustomObj)

[code]...

This all works fine if the webmethod's argument is NOT by ref.With the above mentioned signature of the webmethod, i.e. with a by ref argument, I get a server error (in server response seen using firebub ) -

View 1 Replies

DataSource Controls :: LINQ Buffering Objects When Query On Postback?

Mar 10, 2010

I have a really weird problem. It actually made me restart the computer.

View 1 Replies

JQuery :: Paging Through A List Of Objects?

Dec 20, 2010

I have a list of objects and I would like to create my own custom control that pages through the list using Jquery to make the Ajax calls to my pager methods. I've had some experience with Jquery but need a helping hand and I really don't want to use update panels etc. So the scenario is.....user clicks next, the C# method is called using Ajax, the code gets the relevant data and sends re-populates the UI with the next item in the list.

View 2 Replies

C# - How To Store A List Of Objects In Session

Jun 24, 2010

i want to store a list of objects in session

List<ContentQueueLog> inactiveContent = GetInActiveContent(this.userID, this.visitorID);

when i store this list in sesssion it is stored but while trhying to get its null.

View 1 Replies

How To Make A List Of Json Objects

Mar 17, 2010

I'm using asp.net mvc2 and trying to send a list of json objects with hard coded values from the home controller, and receive them in index.... in the code below i'm sending 1 json object. how do i send many?

in home controller:

[Code]....

View 1 Replies

Caching - How To Cache A List Of Objects

Jan 23, 2010

I have a List of objects in an asp.net page. when the page loads in the browser for the first time, I fetch data from the database, create objects with those data and populate the list. All these are done inside the page load event handler. Now when the page is posted back to the page, the previous list is gone, since the variables were all freed.

How can I cache that List, so that when this page is posted back, all my objects are available?

View 5 Replies

MVC :: Posting A Form With List Of Objects?

Mar 10, 2011

Action method takes as id parameter and returns 2 lists (eg. List<object1> and List<object2>) of objects back to the view. In order to achieve this, the viewmodel is created as below;

ViewModel
{
Int id;

[code]...

View 3 Replies

MVC :: Using RenderPartial To Display A List Of Objects?

Mar 12, 2011

I am making my first attempt at using RenderPartial to display a list of objects, but so far having little success. Here is my code, can somebody give me some guidance on what I am doing wrong?

[Code]....

View 3 Replies

MVC :: Abstracting List Views Of Different Objects?

Dec 20, 2010

I finding myself repeating myself and the DRY side is nagging me to find an abstraction. I have a number of different entities in an MVC3 Razor web app. They are all business objects and each has a number of different properties that I show to the user in a list. So I have Index views and List partial views for each of these different entities (there are at least 10). I would like to abstract the List partial view so that it's capable of displaying a list of any type of entity. It simply shows them in a table with a column for each property and a row for each entity. My current thinking is that I could receive a list of objects and then use Reflection to see what properties those objects have and use those to make columns. I really wish I could receive a generic List somehow and from my various controllers just pass in an anonymous object (new {Parameter 1=param1, Parameter 2=param2}, etc.) but then I discovered that it's not possible to pass anonymous objects around.

View 1 Replies

How To Expose Custom Object (with Sub Objects) In Web Service

Feb 11, 2010

I'm kinda new to web services and want to make sure I am doing things correctly.

I have a custom object which has sub objects as well. (let's say Company object, sub object is collection of Employee objects)

I want the web service to return a collection of Company objects. Do I make the service return a Dataset and custom generate a dataset with datatables representing the different objects?

What is the best way to do this? I tried to just serialize it, but that doesn't seem to work either.

I tried this dll

[URL]

But the output XML doesn't seem to include the sub object.

View 1 Replies

Add Custom Properties Into Control Objects In ExtJs

Jan 25, 2010

How can I add custom properties into control objects in ExtJs.

For example :

[code]....

This control comes from server dynamically and I want to write my custom property as well like below :

[code]....

I tried it but it said undefined. Normally since JavaScript is loose, I can easily modify objects but in this case it wouldn't work the way I expected.

View 1 Replies

Custom Server Controls :: Custom Radio Button Loses State After Postback?

Mar 24, 2010

I have a custom radiobutton and it renders fine but loses state after postback.

How can it be modified?

[Code]....

View 1 Replies

Custom Server Controls :: Custom Control's Children Do Not Persist Contents After Postback

Feb 25, 2011

I have created a really simple custom control to render panels into a page. The code is below. When I use my control and add any webcontrol to it, after each page postback the contents of these child controls vanishes.

I must have missed something really simple but run the example to reproduce this. Can anyone please enlighten me as to why the controls are being 'emptied' of their contents, and how I stop this occuring?

Here is the code for the control

[Code]....

And here's how I am using it in a sample page:

[Code]....

[Code]....

View 16 Replies

ADO.NET :: Create Collection Of Custom Data Access Objects?

Dec 30, 2010

I am using ASP.net to retrieve data from a Lotus notes DB using OLEDB connection. I use a ADOrecordset to read the values. When I open the ADo connection, I would like to store each record being read in a custom object and thereby create a collection of custom objects as ADO connection times out when kept open for long.

I then need to iterate throught the collection of custom objects to retrieve the values.

I am using asp.net 2010

View 5 Replies

WCF / ASMX :: Webservice Custom Objects As Input Parameters?

Nov 9, 2010

I have a fundamental question to ask about web services. I'm currently writing a service that has custom classes (lots of them). Let's say a car is one example. For some reason I was thinking that the service should expose these objects. However once I created a site to consume the service, it looks as though the classes are not meant to be exposed. It looks like the best practice is to take in a string which may be xml or not and convert that string into the object in the service code.(especially for error handling or input validation)

For example, if I had the web method:

[WebMethod]
public car getCar(int carId)
{
//code here to return car object
}

This will take a car ID and return a car object. It also shows all the elements in the SOAP request and response objects (as well as the WSDL) which can be to external developers. However, when trying to consume the service from a website (or reference it in my code), I then need access to the Car class (which implies i need to expose it through the services as well?).

View 5 Replies

C# - Gridview Insert Delete With Custom Objects In Viewstate?

Dec 10, 2010

I want to design a nested gridview with insert, update, delete functionality through custom business objects dynamically inside viewstate.

(Master Gridview)
EmployeeID EmployeeName
1 Ted
(Child Gridview)
ItemID ItemName
1 Keyboard
2 Mouse
2 John
(Child Gridview)
ItemID ItemName
1 PSU
2 GPU
3 Printer

I have done this in the past with datatable/dataviews but they are a real memory hog.

How do I implement Master/Detail functionality with business objects ? What is the alternate to Dataview in master detail/business objects.

I know its a rather broad question but its worth getting started on something =)

View 2 Replies







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