Hi,
I have 3 tables
One table: tbl_applications
app_id
app_name
description
Second table: tbl_applicationGroups
ag_id
ag_name
ag_description
third table : tbl_AGApplications
ag_ID
app_id
I need to insert a record from UI into tbl_applications
in my UI form contains tbl_applications fields(textbox) and tbl_applicationGroups.ab_name(dropdown). I need to insert ag_id, app_id into tbl_AGApplications table.
[HttpGet]
public ActionResult Addapplication(int? appgroupid)
{
if (ModelState.IsValid)
{
var reportGroup = from w in db.SP_GR_Get_appGroupNames()
select w;
ViewBag.reportGroupNames = new SelectList(reportGroup, "RG_ID", "RG_Name", appgroupid);
}
return View();
}
[HttpPost]
public ActionResult Addapplications( tbl_applicationsreports applications, tbl_applicationGroups applicationgroups)
{
ModelState.Clear();
if (ModelState.IsValid)
{
db.tbl_applicationsreports .Add(reports);
db.SaveChanges();
db.SP_GR_InsertapplicationGroupID(reportgroups.RG_ID, reports.Report_ID);
return RedirectToAction("AvailableReports");
}
return View(reports);
}
stored procedure
CREATE PROCEDURE SP_GR_InsertapplicationGroupID
@ReportGroupID int,
@ReportID int
AS
BEGIN
INSERT INTO tbl_applicationsreports([dbo.tbl_GR_RGReports.RG_ID], [dbo.tbl_GR_RGReports.Report_ID])
VALUES (@ReportGroupID ,@ReportID )
END