Question

I have a problem with a model in a asp.net mvc3 application. First of all, i have a table with items, each item has e.g.: id,name and description where i also have a user with: id, name

It looks somewhat like:

class item {int id, string name, string description}
class user {int id, string name}

Now i also have a table which maps these two things to each other, with foreign keys. so each user can have * items and each item also can have * users.

Now i need to create controller and view for the item. this works fine, the problem is, that i just create a item, but i want to create a item and the mapping to a user in one step.

how to solve this problem in mvc? (e.g. i just can add one model in a view and this is the item in the create process)

Was it helpful?

Solution

Short answer: you need to add drop-down of users while creating an item. This will help to link each item to a user.

However, your particulate issue seems to be in building many-to-many relationship in the model. How to do this? Well, this is already nicely explained here - ASP.NET MVC, Entity Framework, One-to-Many and Many-to-Many INSERTS

In addition, I would strongly suggest to go through - NerdDinner Tutorial. It will give you good start-up and solid background for development in asp.net mvc framework. You may also refer to Tutorial samples in official website to learn and practice development in mvc.

Here is a link to complete code of the tutorial - NerdDinner 2.0 Complete ASP.NET MVC Sample App

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top