0

Hi i am having problem inserting data into multiple table from one view. First understand the scenario: I have a student table and a student name table. Name table contains Firstname, Middlename, Lastname. Student table contains a foreign key of name table Id. I made a data model by ADO.net. Now how can i pass both Student and Name data to the Create student View?

//StudentsController: Create View [GET Method]

    public ActionResult Create()
    {
        return View();
    }

//Create View

Inherits="System.Web.Mvc.ViewPage<DomainModel.Models.Student>"

1
  • Create should use post method not get. Commented Nov 20, 2009 at 7:43

1 Answer 1

1

You could either a) create a strongly type class that encompasses both the student and student name table

class StudentViewData
{
  Domain.Models.StudentName Student { get; set;}
  IEnumerable<StudentTable> Students { get; set;}
}

and pass this in to your view

or b) use

ViewData["StudentTable"] = DomainModel.Models.StudentTable

and in the view

foreach(var s in (DomainModel.Models.StudentTable )ViewData["StudentTable"]) ...

me personally I would use a)

I am making a couple of assumptions of your model from your explanation.

Sign up to request clarification or add additional context in comments.

4 Comments

i also think a) is a good idea. But as a beginner it is quite difficult to me. Can you show me a little elaborately?
I have just started my code. It was the beginning. Student Table Contains student iformation. Id, Name, address, dob etc. Name and Address are multivalued attributes. So i defined two tables for them "StudentName" and "StudentAddress" and put the foreign key reference of these tables in Student table; Now if i want to add a new student, i have to add StudentName and StudentAddress first. I hope you can understand. Now i want to create a create form where student can enter information. And the entered information will be save din different tables that means StudnetName, StudentAddress, Student.
Please help me out. I need some materials so that i can learn how multi table(related) insertion is done...
I suggest learning more about MVC. see asp.net/mvc and click the "Learn" link. I am not sure still about your data structure. IF you are using Datasets/Datatables then I suggest you learn about how to populate the strongly typed classes from this. Sorry but I cannot be of more help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.