MVC :: How To Add Product To Category (Many-to-many Relation)
Feb 16, 2011
I'm trying to add a product to one or more categories, but I'm going nowhere slow.
Table layout:
[Code]....
[Code]....
[Code]....
I been trying everything to add a product to a category, but without luck. I would have though this was the "right" way:
[Code]....
On my "Create" product page, the product is created but I just can't find a way to link a product to one or more categories. It just skips back to the Create page, even though I have put a Redirect in the Controller.
i create example using Northwind database so i create a new website and add new ADO.Net Entity Data Model (.edmx) called Northwind.edmx and i add Categories and Products table inside this (.edmx) file
and add new ADO.Net Data Servuce called "ADODataService" and add it as WebReferences called NorthwindService
so i add new web page and drag DropdownList and Gridview as i want to bind Dropdownlist to all categories and when i select category from Dropdownlist bind Gridview to all Products related to this category
so my code
[Code]....
and my code [Code]....
so when i select category from Dropdownlist nothing happen :(
also you will find commented code in method BindCategory whuch is not work also.
I'll try to explain as simple as I can in text what my problem is. I don't see any other way to make my issue clear.
I have a GridView that uses an ObjectDataSource.
The ObjectDataSource has an DataObjectTypeName defined, so I pass/get complete objects or list of objects to/from the data access methods.
The objects I'm working with, let's say we work with Book objects, contain a Title and a Category, BUT the Category is an object itself. When the Select method is called, we get a List of Book objects, which is perfectly displayed, overridden ToString method in the Category objects within the Book objects.
The problem I face is that I can't find a way to update the category in my GridView. What I did already accomplish is:I used a template field in the GridView for the Category so I could use a DropDownList for that field in Edit mode.
I bound the DropDownList to another ObjectDataSource that gives me a list of CategoryObjects.
So when I enter Edit mode... the row shows a nice ddl with the available categories. It even selects the right original category.
So far so good... but when I want to save my new selection, I get an error that a string (the selected category in the ddl) cannot be converted to a Category object (that's what the Book object, that is going to be used for the update, expects).
I am working in a project that is a musical website. I want to display the web page with all categories I have. In my database , named Category_Master, I have two fields like Category_Id (which is a primary key ) and Category_Name. I have generated category_Id with NEWID() function. The category_Id is not supposed to display on the web page. But, i have to select Category_Name and according to that , I have to get the category_Id. If I am using Static connection with SqlDataSource, i am able to make visible=false property so that the category_id won't be visible. But , at that time, I can't write code to Select the category_id of the selected index.
If i am using disconnected approach, I filled the dataset with the Category_Master, and binded it to GridView. But, at that time, I can't hide the category_id from the user. I want to select category_id by clicking on the category_name with out displaying category_id ..?
Then I tried to retrieve node type from Node this way - Nodes node = Entities.Nodes.First(); string nodetype = node.NodeTypes.Name; but for some reason node.NodeTypes equalls null despite fact that there is some records in NodeTypes table.
I see that there is no Check-Ins on ASP.NET MVC Storefront code since Feb 7th. And on this question, Orchard project link is given with the answer. Is there any relation between these two projects?
I am asp.net newbie,I used to write in Python and Django.I have very small app with two models: [Code]....
and in database I have also created TeachersSubjects table with 2 fields as foreign keys (TeacherID, SubjectID).So my question is: what should I do now? Should I define another model like TeachersSubjects, or are there any other ways to define this relation?(I prefer to stay with handwriting classes, rether than Visual Studio magic.
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?
I have 2 table in my db kategori(category) and alt_kategori(subcategory). it have a relation kategori to altkategori.I can add kategori but i cant add altkategori i take this error participate in the 'KategoriAlt_Kategori' relationship. 0 related 'Kategori' were found. 1 'Kategori' is expected.
i am working on a social networking project using MVC2 visual studio, currently i am working on these two tables , post & comment. Each post can have many comments.i have created a post controller along with the related view , and it work well , now i want to add under the post a comment view, where a post can have many comments , i can add the comments on different view , but i need to have a post and under it to add many comments, so how i can do so?
another problem is that in the post table there is a field representing a rating, now i can add in the rating field 1, 2,3,4,5,etc, but i need this field to be viewed as a list having values from 1-5?
I have a MVC project wich uses LINQ to SQL as a data layer.
For example, I have a tables ProductGroups and Products. Product is a child of ProductGroup, so to get name of ProductGroup, in aspx-page I use constuction like Model.ProductGroup.Name.
But when I delete a ProductGroup there is appear a NullReference Exception in presentation page.
While I was using just DataSet and manual SQL-queries, the rows, there was not every joined-element present, simple were not put in query result.
I know that before delete Parent row I have to delete all children rows, it's correct way.
1. Is there a way to ignore rows which has null-elements without manual checking through "IF"?
2. Is there simple way to delete all dependencies without manual enumerating every related tables?
I have an application which has rows of data in a relation database the table needs a status which will always be either Not Submitted, Awaiting Approval, Approved, Rejected Now since these will never change I was trying to decide the best way to implement them I can either think of a Status enum with the values and an int assigned where the int is placed into the status column on the table row.
Or a status table that linked to the table and the user select one of these as the current status.
I can't decide which is the better option as I currently have a enum in place with these values for the approval pages to populate the dropdown etc and setup the sql (as it currently using to Approved and submitted for approval but this is dirty for various reasons and needs changed).
Wondering what your thought on this were and whether I should go for one or the other.
If it makes any difference I am using Entity framework.