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


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

C# - Attaching Validation To EF Objects Used In MVC Controllers/views?

Feb 11, 2011

We're throwing together a quick project (CRUD forms) and decided to skip view models and use EF entities directly in controllers and views. Since I'm not used to this approach, I'm confused about handling validation.

For example: a DB field has a length of 25. How does that get transferred (if it can) to a validation constraint in my view? If i was using an intermediate model, I would attach attributes to the model properties and it would work. How would I do this using EF objects directly?

View 3 Replies

MVC :: Handle Strongly Typed Views If Have Multiple Objects/models?

Mar 16, 2011

<p>Hi</p> <p>I'm a newbie in MVC but a veteran web forms developer. I really like the idea of strongly typed views but what if I have multiple objects to pass to my razor view. Would I then NOT use strongly typed views and just use the ViewBag?</p>

View 3 Replies

Architecture :: Abstracting Web Services?

Jul 25, 2010

I have 2 web services. They are identical in every respect except that one points to a test schema and the other one to production. I'm in the middle of writing the class that will use these web services but I'm not sure how to do what i'm trying to do.What I need is a class that does the work of consuming the web serivce, and I want to pass to it either the test or prod serice and and it be transparent insde of the class.

So..testSerive and prodSerice are idential, how can i have them inherit from something so that i can pass that something to my consumer class?

View 2 Replies

C# - Object Oriented N-tier Design Abstracting Too Much?

Jun 8, 2010

I'm building my first enterprise grade solution (at least I'm attempting to make it enterprise grade).I'm trying to follow best practice design patterns but am starting to worry that I might be going too far with abstraction.

I'm trying to build my asp.net webforms (in C#) app as an n-tier application.I've created a Data Access Layer using an XSD strongly-typed dataset that interfaces with a SQL server backend.I access the DAL through some Business Layer Objects that I've created on a 1:1 basis to the datatables in the dataset(eg, a UsersBLL class for the Users datatable in the dataset).I'm doing checks inside the BLL to make sure that data passed to DAL is following the business rules of the application.That's all well and good.Where I'm getting stuck though is the point at which I connect the BLL to the presentation layer.For example, my UsersBLL class deals mostly with whole datatables,as it's interfacing with the DAL.Should I now create a separate "User" (Singular) class that maps out the properties of a single user,rather than multiple users?This way I don't have to do any searching through datatables in the presentation layer,as I could use the properties created in the User class.Or would it be better to somehow try to handle this inside the UsersBLL?

below is the code from the UsersBLL:

using System;
using System.Data;
using PedChallenge.DAL.PedDataSetTableAdapters;

[code]...

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

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

MVC :: Create Multiple Views For Essentially The Same Type Of List?

Jan 31, 2011

If I have a View for 'People' and a View for 'Company' and each has an associated list of 'Orders', should there be a separate view for each? Such as /People/Orders and Company/Orders, or should I simply have a single /Orders views and pass in some parameters?

View 9 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

Sorting A List Of Objects By An Object's Field?

Mar 25, 2011

Let's say I have the following class:

[Code]....

Now let's say I have a list of these objects.

[Code]....

How can I sort this book list by the Book object's BookID property?

View 1 Replies

MVC :: Load Partial View With List Of Objects?

Jul 8, 2010

I'm really new to MVC (just started a few weeks ago) and new to Ajax (never looked at it before today). I need some design / technical advice concerning Ajax, MVC, loading partial views, and posting / getting from a view. What I'd like to do it load a partial view that takes in a list of objects that have been queried from my db into an details-type view. The details view already has some other content that has been handeled and loaded from information pulled from my database and setup through some actions. It is strongly types to a model.

Below is the partial view I've created thus far:

[Code]....

And here's a portion of the Details page:

[Code]....

I'm not sure what to do for the Ajax.ActionLink. I'd like for a use to be able to type into the text box on it's left and hit "Add" (the Ajax link) and have the application add the content in the text box to the database. Should it be something else? An <input>? The Controller code piece is below:

[Code]....

So it should be adding the member into the repo / db and then reload the contents of the partialview. Instead, it's reloading the whole page and not just the partial view. (the url is changing from /project/details/5 to /project/membersection/).

View 10 Replies

ADO.NET :: Creating Dataset Using List Of Objects In Linq?

Oct 27, 2010

I am using Linq To Sql to get List of objects with data from database. To bind data with a grid view i am creating a dataset explicitly and then adding List values to that explicitly created dataset.

Now my question is whether it is a good pratice to do what i am doing (in terms of resource utilization) or is there any better way to this...

View 6 Replies

Populate A Generic List Of Objects In C# From SQL Database?

Mar 16, 2010

I am just learning ASP.NET c# and trying to incorporate best practices into my applications. Everything that I read says to layer my applications into DAL, BLL, UI, etc based on separation of concerns. Instead of passing datatables around, I am thinking about using custom objects so that I am loosely coupled to my data layer and can take advantage of intellisense in VS. I assume these objects would be considered DTOs?

First, where do these objects reside in my layers? BLL, DAL, other?

Second, when populating from SQL, should I loop through a data reader to populate the list or first fill a data table, then loop through the table to populate the list? I know you should close the database connection as soon as possible, but it seems like even more overhead to populate the data table and then loop through that for the list.

Third, everything I see these days says use Linq2SQL. I am planning to learn Linq2SQL, but at this time I am working with a legacy database that doesn't have foreign keys setup and I do not have the ability to fix it atm. Also, I want to learn more about c# before I start getting into ORM solutions like nHibernate. At the same time I don't want to type out all the connection and SQL plumbing for every query. Is it ok to use the Enterprise DAAB for now?

View 2 Replies

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

VS 2010 - How To Write List Of Objects To CSV File

Mar 13, 2013

Nothing I find on the Internet is working.This is the closest I've gotten. It produces an output file without exceptioning but the output file has blank lines. But it's the correct number of blank lines.

Code:
public void WriteCSV<T>(IEnumerable<T> items, string path)
{
Type itemType = typeof(T);
var props = itemType.GetProperties(BindingFlags.Public | BindingFlags.Instance)
.OrderBy(p => p.Name);

[code]...

View 2 Replies

C# - Paging Through A List Of Objects And Repopulating Using JQuery AJAX

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 1 Replies

Forms Data Controls :: Gridview With List Of Objects?

Feb 5, 2010

I have a List of Customers. Now I want to display these customers in a gridview and that is easy. I just set the datasource and use the databind method of the gridview. (I use template fields). But now I want to display FirstName and LastName of the customer as one column.I am aware of how to use the rowdatabound event to manipulate the gridviewrow's controls, but I am not sure how to gain access to the customer object within this method.So here is some code which of course not works.

protected void grdVirtualCustomers_RowDataBound(object sender, GridViewRowEventArgs e)
{
System.Web.UI.WebControls.GridViewRow row = e.Row;

((Label) row.FindControl("lblName").).Text=Customer.FirstName + " " Customer.LastName;
}

View 2 Replies

MVC :: Passing A List Of Entity Objects To View From Controller?

Aug 5, 2010

I need to pass a list of Entity Objects from Controller to View but not put it in the Model context. It is the users homepage, but I am putting a list of alerts on the users home page(somewhat like facebook). So I need the User Context as the Model I pass but need to pass the Alert model as well so I can show the list of alerts.. How would I do that? The code below is what I have so far..

UserController

[Code]....

UserRepository

[Code]....

View 1 Replies







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