开发者

multiple table insert ASP.net MVC

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 C开发者_如何转开发reate student View?

//StudentsController: Create View [GET Method]

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

//Create View

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜