获取添加项的ID(ASP.NET MVC)

时间:2017-10-06 20:37:39

标签: c# asp.net asp.net-mvc

我有从ajax调用

向db添加新项的方法

这是后端方法

public ActionResult AddingInternalAppointment(string Start, string End, string Title, DateTime appointmentDate,int id)
{
    using (var ctx = new ApplicationDbContext())
    {                    
        Appointment appointmentInt = new Appointment()
        {
            Start_appointment = Start,
            End_appointment = End,
            Title = Title,
            Type_of_appointment = "Internal",
            Date = appointmentDate
        };

        ctx.Appointments.Add(appointmentInt);
        ctx.SaveChanges();
        return Json(new {Result = "Success", Message = "Saved Successfully"});
    }

我需要获取已创建项目的ID并将其写入变量。

我怎么能这样做?

0 个答案:

没有答案