Combine Data From Multiple Tables Into One View Model
Dec 5, 2010
I'm fairly new to all this, but have slowly been teaching myself C# and ASP.net MVC over the past year or so...I really tried to search for this, but haven't been able to find anything - it may be I'm using the wrong terminology!I'm using ASP.NET MVC2 with EF4 connected to a SQL Express db. Situation: Without getting into too much specifics, I have one table called 'Plan.' Under 'Plan' are several different categories that are related to a single Plan item [say Category A, Category B, Category C and Category D]. Each 'Category X' table has a beginDate, endDate and other details specific to that category.
I'd like to be able to create a summary page that combines all items from Category A, Category B, Category C, and Category D and sorts by beginDate - but only need a few of the columns [eg - begin/end date, name, id].
View 1 Replies
Similar Messages:
Aug 26, 2010
one thing that has been puzzling me since learning MVC2 is the following case scenario: I have a view which contains two latest news lists, a login form and a signup form. Every example I found on Views and View Models so far has a one-to-one example such as a simple login form etc. But how do I create a model that provides the properties and validation for a login and signup form and manages the data for the news lists. can I pass multiple models in the strongly typed view? When I created one model the form validation would fail as it expects all fields - login and signup to be filled. I am missing some advanced examples or information.
View 2 Replies
Nov 30, 2010
I am having a hard time solving the following with an MVC view. My goal is to display data from multiple tables in a single MVC view. The bulk of the data comes from a table called Retailers. I also have another table called RetailerCategories which stores the retailerid from the Retailers table and also a categoryid linking to a Category table. Note that there are multiple records for each retailerid in the RetailerCategories table.
In the view I want to show a list of retailers and with each retailer I want to show the list of categories applicable to them. What would be the best way to accomplish this?
View 2 Replies
Feb 23, 2011
I have one view page (MyView.aspx) and many data sources to bind on this page. Lets say it has Books, Publishers, Comments, etc. Each one of those has an object which provides a List, List, etc. In my view, what are my optiosn for multilple model biding? I want to check to see if each one is empty, and then enumerate it. But I can't check Model.Count() because wouldn't Model be made of all those objects if I set the page to inheriet from? What are my options? Should I load each content area in a control/partial view? Or can I just dump each object into ViewData and then check the count by casting in the view?
View 2 Replies
Mar 27, 2010
I have 2 tables with UserId and FirstName, LastName Columns that I want to combine the data in a Select Statement or Stored Procedure
1. The 2 tables will never have the same data, each table will be distinct
2. I want to combine first and lastnames to a full name (t1.FirstName + ' ' + t1.LastName) AS FullName
3. The statement will be used to populate a dropdownlist with UserId as Value, and Name as text
I am unsure how to accomplish this since I do not need to connect the tables, but combine the Sum of their data.
View 6 Replies
Jul 10, 2010
I have a Order view with 2 user controls in it.
The first user control in the view is just to validate the customer and get some more details about the customer. This control is having one text box (customer name) with the button. When the user clicks the button it should validate the customer name in the client side using data annotations of customer model. if validation success then it should use some bussiness logic to verify the customer and show the customer details on the form.
The 2nd user control in the view is to get the address of the customer by searching for the house no and the postcode. This control is having 2 text box with the button.
The first user control is based on the strongly typed customer entity
The 2nd user control is bsed on the strongly typed address entity
The view with both the user control is based on the strongly typed order entity.
The issue here is with the validation. I have the validation summary in the view and client sider validation is enabled. When i click the search button on the first user control the client validation starts and throws validation error messages because when i search for the customer at that point of time i will not have values to may of the customer related fields in the order view.
The same thing happen when i click the search button on the 2nd view. It will throw client side validation for other fields.
What i want to achive is that when the user click the search button on the user control 1 then the validation should happen only to the customer name field (both in client and server).
When the user click the search button on the 2 nd user control the the validation should happen only for houseno and the postcode both in client and the server.
When the user clicks the save button on the order view all the fields in the form even the controls usere input fields should get validated. How to achive this in mvc?
View 4 Replies
Jan 27, 2011
This project I'm working on have this custom clientside JavaScript validation framework created for (which I cannot change) that show error messages/summary based on your data annotations and a "Validate" method in your ViewModel.
Like I said I'm not allowed to change this, so wont be able to go with suggestions doing that.
What the person that created this did not foresee, is that one might need put several partials of the same type and having the same view model (each in a form) on a view.
So I went ahead and did things the normal way (using Html.whateverFor<model => model.whatever) and wala!....the custom validation thing throws error messages for the specific form fields, next to each form in the view. I was suggested to create a "prefix" for each instance of the view model, and do something like this:
Change: <%: Html.HiddenFor(model => model.AccountNumber)%>
To: <%: Html.Hidden(Model.ElementPrefix + "AccountNumber", Model.AccountNumber)%>
Not to mention the tons of jquery selectors and all that I have to go change (and all my view inputs)
(I just hate having to find workarounds for this "custom" everything they created for this project)
View 9 Replies
Jan 8, 2011
The main problem is that I recieve the following message:
"base {System.SystemException} = {"Unable to create a constant value of type 'BokButik1.Models.Book-Author'. Only primitive types ('such as Int32, String, and Guid') are supported in this context."}"
based on this LinQ code:
[Code]....
How shall I solve this problem to get a class instance that contain with property title and Book-AuthorID?I also have tried making some dummy by using "allbooks" relation with Code Samples from the address
http://www.hookedonlinq.com/JoinOperator.ashx. Unfortunately, still same problem.
I also have taken account to Int32 due to entity framework http://msdn.microsoft.com/en-us/library/bb896317.aspx. Unfortunatley, still same problem.
Using database with 3 tables and one of them is a many to many relationship. This database is used in relation with entity framework
Book-Author
Book-Author (int)
BookID (int)[code]....
View 1 Replies
Dec 15, 2010
I've been used to decorating data model classes with data annotation attributes, but the purist in me baulks slightly at including purely presentational attributes such as display format here. I am, however, quite happy to keep validation centric attributes here. One good reason I have to continue keeping all annotations etc. in the data model is that my view model aggregates data model classes, e.g.
my ViewModelBase.DetailItem<TEntity> property in the view model is just a reference to an entity class in my data model. If I wanted to move presentational annotations to the view model, I would have to quite radically revise my design to one where I duplicate data model properties in my view model and use an object mapping tool to populate view model objects based on data model objects.
[code]....
View 2 Replies
Feb 5, 2010
I am writing a currency converting module for one of our applications. I have a list of products, a list of currencies we are interested in seeing prices for, and a list of currency rates. I want the user to be able to select which currencies from the list they see in the GridView. I also want to be able to amend my list of currencies and include a new currency, without having to make additional changes to this module. So my GridView display has to be "dynamic". Essentially I am planning on ending up with a GridView that has the following columns:
Part No - Description - USD Price - AUD Price - GBP Price
The USD price would be static as it's our base currency, the AUD and GBP are user selected and could have potentially any number of currencies listed. I would normally use a DataSet and DataTables for this work, but I am sure there is a "better" way to do it using System.Collections.Generics. Right now I have all of the data I need in List collections, but there does not seem to be a way to define how these collections relate to each other, or combine these collections into one so it can be bound to a GridView. Should I be looking at something other than List to achieve this or do I need to go back to my original approach of a DataSet and DataTables.
**UPDATE / SOME CODE**
I will explain a little bit more about what I have setup so far.
1) List of Products & Currencies - These come from an SQL DB via LINQ, so they can be any of the System.Collections.Generics objects, e.g. List, IEnumerable etc.
2) Currency Rates - These I am pulling from the European Bank public XML file. I download the file, strip the data I need out of it and currently store that as a List object.
I could store the currency rates in the database table as well, but then I have to have some sort of background process that goes and updates the rates each day. This way the rates only get updated when someone accesses the report function (which is only going to happen occasionally). So I would rather grab the latest rates "on demand". What I know I need to end up with is some object that has the following structure:
PartNo - Description - Base Price - Currency Price 1, Currency Price 2, Currency Price 3
Where the number of Currency Prices is undefined, as it's based on what currencies the user wants the report to display. It's the undefined part that I am struggling with, essentially how can I create a structured object, that I don't know the complete structure of until runtime?
View 1 Replies
Feb 4, 2010
I have 2 tables and I want to entries of the tables into something like this:
Table 1: Table 2: End Result:
a 1 a - 1
b 2 a - 2
... ... b - 1
... ... b - 2
... ... ...
View 3 Replies
Jun 2, 2010
I have been reading about different model for development
model view control mvc
model view presenter MVP
Model view view model MVVM
i belive MVC has two big Advantage over webform 1) TDD 2) More control on HTML
MVP is bit variation in mvc model. rapid development as well as 1) TDD 2) More control on HTML (correct me if i m wrong) see the below link
[URL]
View 7 Replies
Mar 9, 2011
I have a repeater like so:
[Code]....
Problem is, I also want to show the viewer the available number of spots in the room. But this requires somehow pull in either the current_occupancy / max_occupancy or in performing a calculation (e.g. max_occupancy - current_occupancy = actual_available) and then returning that with the room.
The end result I'm looking for is to return each room in a button control with text that looks like this:
"Room 1 - 2 Open" "Room 8 - 1 Open" and so on
View 2 Replies
Aug 12, 2010
when i create my entity data model i have a situation in the DB like this :
TableFirst : [Id,IdTableSecond,IdTableSecondAgain];TableSecond[Id]
Created data model is: TableFirst.TableSecond and TableFirst.TableSecond1
Question is: Every time when i create my entity TableFirst.TableSecond will have same relation in behind (IdTableSecond) and TableFirst.TableSecond1 (IdTableSecondAgain)
or they may change?
View 1 Replies
Apr 6, 2010
my application have two tables. TableA and TableB TableA have one record
ID StudentName Age
1 MARK 20
I use selectlist to select StudentName .
ViewData["StudentName"] = new SelectList(_db.StudentSet.ToList(), "StudentName", "StudentName");
and then add to TableB. for this case , for me is success, but I also want to add the"Age" into TableB on same time. I don't know how to do it.
View 3 Replies
Jul 22, 2013
I created 3 product table . A,B and c.
I show product of table in different gridview.
Now I am using one search box. but how to search product name with image in one query all of three table....
Simple how to search product from multiple table and show result...
View 1 Replies
May 7, 2015
I have storedprocedure which returns four or more dataset!
example here
How load and display all data in Default.aspx....
dataset 1
............................................
dataset 2
............................................
dataset 3
............................................
dataset 4
............................................
View 1 Replies
Jul 7, 2010
Really new to C# & Web developing - but have used the DAL & BLL model from a number of the turorials. Have a situation that I not sure the best way to accomplish. I have an application dealing with courses, books, etc. utilizing an Access Database. All was going well in creating an on-line catalog using Formview and tables to display the db values stored in the Course Table (Course ID the key). User is able to use dropdown list to locate the course - dropdown list showed the Course Nbr & Name, but used the Course ID to get the detail. This issue appeared when they introduced a Prerequisite field in the Course Table. This contains the Course ID of the prerequisite course, but they want to display the Course Nbr and Name in the table field. So today it show 18 (Course ID) and they want B101 Intro to Biology. Hope I have provided enough information of what the code looks like below
Here is the FORMVIEW & TABLEROW
<asp:FormView ID="FVGeeralidades" runat="server" DataKeyNames="ClaveAsignaturas"
DataSourceID="ObjectDataSource1">
<ItemTemplate>
<asp:TableRow ID="TableRow5" runat="server">
<asp:TableCell ID="TableCell11" runat="server" HorizontalAlign="Left" Text="<STRONG>1.6</STRONG> Prerrequisito"
Width="150px"></asp:TableCell>
<asp:TableCell ID="TableCell12" runat="server"></asp:TableCell>
<asp:TableCell ID="PrerrequisitoValue" runat="server" HorizontalAlign="Left">
<%# Eval("AsignaturaPrerrequisito")%>
</asp:TableCell>
Here is also the OBJECT DATA SOURCE
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" OldValuesParameterFormatString="original_{0}"
SelectMethod="GetCourseByCourseID" TypeName="CoursesBLL">
<SelectParameters>
<asp:ControlParameter ControlID="DDLCourse" Name="CourseID" PropertyName="SelectedValue"
Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
View 1 Replies
Jan 4, 2011
I have an C# ASP application I am writing that needs to have the capability to import a generated excel or a comma delineated sheet each day. A clerk will have this job each morning so it doesn't need to be automated. My problem in trying to understand the solution to this is that the 1 sheet contains loan information, including customer information all in the same sheet. I would like to send certain columns to update information in the loan table and send other information to update the customer table. I need it to create relationships when new loans appear in the spreadsheet.
View 1 Replies
May 4, 2010
Say I got a domain model as follows: (and my repository expect an instance of this object)
[Code]....
And a view model (which my views are based on)
[Code]....
At the moment I got it like this and have my controller action manually create a new Person object from the PersonModel object before passing it on to the repository, which does not feel right.
So I tried to have PersonModel inherit from Person and pass that to the repository (also tried casting the PersonModel to a Person object first), but that don't work out.
What's the right way to have PersonModel automatically cast to Person? I want to keep this logic as my current structure allow me to keep things really loosely coupled, with the repository layer not having a clue how it's being used.
View 1 Replies
Mar 3, 2010
I have 4 different select statements which i sequently assign to an sqlDataSource like this:
sqlNoutatiProduse.SelectCommand = select;
and i keep the results in different DataViews like
MySession.Current.dataViewNoutatiProduse1 = (System.Data.DataView)sqlNoutatiProduse.Select(DataSourceSelectArguments.Empty);
Is it possible to combine into a single DataView the results of these queries?
View 1 Replies
Feb 2, 2011
I am developing in asp.net mvc and using multiple javascript files.eg jquery, jquery-ui, google-maps my own js files etc.for performance should i combine these into one?if so how?
View 4 Replies
May 8, 2010
Working in Access, I need to create a view which takes values from two different records in another table and puts them on one row in the view. I'm having a hard time doing this since both row items come from the same field in the original table (actually in this case, using views instead of tables).
I have two queries I try to join together, but come up with the wrong results:
vwComp1:
SELECT q.CompStatus, q.EQID, c.CompsID, q.LastName, q.FirstNameFROM _EQ AS q, Comps AS cWHERE q.CompStatus=1 AND c.CompsID=q.CompID
vwComp2:
SELECT q.CompStatus, q.EQID, c.CompsID, q.LastName, q.FirstName
FROM _EQAS q, CompsAS c
WHERE q.CompStatus=2 AND c.CompsID=q.CompID
vwAssignment:
SELECT vwComp1.*, vwComp2.*
FROM vwComp1, vwComp2
This does fine in the vwComp2 part of vwAssignment, in the sense that it displays the correct name information, etc.; but for vwComp1, it just takes the name and other fields from the first row of vwComp1 and repeats it on every row of vwAssignment. This is really strange because vwComp1 and vwComp2, when displayed individually, each correctly puts the names in each row; something like this:
Bob White Rhonda Red
Bob White Freda Freschetta
Bob White Linda Lime
Bob White Jean Green
--when it should read something like this:
Bob White Rhonda Red
Fred Redd Freda Freschetta
Jim Brown Linda Lime
Rob Black Jean Green
View 1 Replies
Apr 1, 2010
Is there any way to combine multiple Audio Files (.wav etc) into one file?
I have found an example here :
[URL]
Quote:
[code]....
View 1 Replies
Dec 13, 2010
have been unable to find any explanation of this anywhere.I have an .ascx partial view that's pulling data from a given model.I want to populate a drop-down list in my partial view using data from a table
outside the model (it is in the same database and entity framework).I don't know the syntax (I'm pretty much just learning MVC2 and jquery), and don't even know where to start. I've gotten about as far as <% foreach step in [???] %>, but don't know what to do with it. What do I put in the "[???]"???
View 6 Replies