如何将值从一个视图传递到另一个视图 [英] How Do I Pass Values From One View To Another View

查看:111
本文介绍了如何将值从一个视图传递到另一个视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是非常新的ASP.NET使用MVC控制器...所以这是我的场景。



我正在开发一个在线入学系统,学生来这里填写在他们要求处理的记录中...



i不同的班级,其中包含有关学生的具体信息。我的学生班级是



  public   class 学生
{
public int ID { get < /跨度>; set ; }
[必需]
public string 名称{获得; set ; }
[必需]
public string FIRSTNAME {获得; set ; }
[必需]
public string LASTNAME {获得; set ; }
public virtual ICollection< Enrollment>注册{获取; set ; }
}



i还有另一个名为Enrollments的课程,用户可以输入所有课程以及成绩

  public   class 注册
{
public int EnrollmentID { get ; set ; }
public int CourseID { get ; set ; }
public int StudentID { get ; set ; }
public 年级{ get ; set ; }
public virtual 学生学生
{
获得;
set ;
}
public virtual 课程课程{获得; set ; }
}
public enum 等级
{
A,B,C,D,E,F
}
}



和更多不同的课程。

我有一个名为Registration的CONROLLER,我将为每个类创建视图。



SO在我的第一个视图中获取所有学生详细信息,之后记录已保存。

当用户点击下一步时,我想将学生类的ID号传递到我的下一个视图,即注册视图,并保存记录以及ID号学生班在注册课程和数据库中充当foriegn键。



一直在努力实施2但没有成功。我会很感激示例说明如何实现这一点因为我最近开始使用ASP.NET时使用mvc框架并不太好..



请我真的需要帮助的人..谢谢你有一些方法可以使用ViewBag,ViewData或TempData。

,使用ViewBag。


传递数据视图之间 [ ^ ]

I am very new to ASP.NET USING MVC Controllers...so here is my scenario.

Am developing an Online Admission system where students come and fill in their required records to be processed for admission..

i different classes that holds specific information about the student..my student class is

public class Student
    {
        public int ID { get; set; }
        [Required]
        public string NAME { get; set; }
        [Required]
        public string FIRSTNAME { get; set; }
        [Required]
        public string LASTNAME { get; set; }
        public virtual ICollection<Enrollment> Enrollments { get; set; }
    }


i have another class called Enrollments where the user Enters all the courses as well as the Grade

  public class Enrollment
    {
        public int EnrollmentID { get; set; }
        public int CourseID { get; set; }
        public int StudentID { get; set; }
        public Grade Grade { get; set; }
        public virtual Student Student
        {
            get;
            set;
        }
        public virtual Course Course { get; set; }
    }
    public enum Grade
    {
        A,B,C,D,E,F
    }
}


AND different more classes.
I HAVE A CONROLLER called Registration, where i will create the views for each Classes.

SO IN my first View which takes all the student Details,after the Record has been saved.
when the user Clicks next,i want to pass the ID number of the student class to my next view which is the Enrollment View and save the records along with the ID number of the student class which is acting as a foriegn key in the enrollment class and database.

Have been trying so hard 2 implement this but with no success.I would appreciate a simple example to demostrate how to achieve this becos am not too good using the mvc framework as i recently started using ASP.NET..

please i really need help guys..Thanks in advance

解决方案

There are some ways to do this - you can use ViewBag, ViewData or TempData.
If you are using MVC4 or higher, use a ViewBag.


Passing data between views[^]


这篇关于如何将值从一个视图传递到另一个视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆