我有面试和采访
当我创建面试时,我需要生成视图中的链接,并将其发送到interwier。
因此,如果Interview_id是=5,那么面试官将接受id=5的面试
Table Intervier与面试表相关联。
这是面试官表
CREATE TABLE [dbo].[Interwiers] (
[Interwier_id] INT IDENTITY (1, 1) NOT NULL,
[FIO] NVARCHAR (MAX) NULL,
[Email] NVARCHAR (MAX) NULL,
[Telephone] NVARCHAR (MAX) NULL,
[Birthday] DATETIME NOT NULL,
[City] NVARCHAR (MAX) NULL,
[Salary] NVARCHAR (MAX) NULL,
[English] NVARCHAR (MAX) NULL,
[Interview_Id] INT NULL,
[Status] NVARCHAR (MAX) NULL,
PRIMARY KEY CLUSTERED ([Interwier_id] ASC),
CONSTRAINT [FK_Interwiers_ToTable] FOREIGN KEY ([Interview_Id]) REFERENCES [dbo].[Interviews] ([Interview_Id]) ON DELETE CASCADE现在,我生成类似这个http://localhost:51542/Interwier/Welcome的链接,我需要类似于这个'http://localhost:51542/Interwier/Welcome/5‘这样的smth,所以如果Interwier在Interview_Id中自动填充表中的数据,那么例如id=5。
我怎么能意识到这一点?
也许我没写清楚我的问题。如果没有,请告诉我,不清楚,我会编辑它。
更新
这是Interwier的控制器,这里我将数据写入表
public ActionResult Welcome()
{
return View();
}
// POST: Interwier/Create
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Welcome([Bind(Include = "Id,FIO,Email,Telephone,Birthday,City,English,Salary")] Interwier interwierModel)
{
if (ModelState.IsValid)
{
db.InterwierModels.Add(interwierModel);
db.SaveChanges();
return RedirectToAction("WebCamCheck");
}
return View(interwierModel);
}UPDATE2
我试着写逻辑
这里是开始屏幕,这里我创建了面试(选择空缺并编写有关面试的详细信息),所以我创建了Interwiev id。就这样办。

之后,我创建问题并将它们添加到面试中,然后单击next并将问题添加到表中,并链接到Interview_id。
这是模型

在那之后,我需要向人们发出邀请。还有下一个模特儿

在“链接”中,我需要生成“链接到面试”,而不是像我以前写的那样。
我需要用id生成它。因此,用户打开它,并填写有关他的信息,它将链接到这个面试ID。
发布于 2017-03-24 09:18:09
如果您正在使用实体框架来保存数据,那么就可以这样做了。
假设Interwiers表只有两个像Id和name=这样的列
DemoEntities db = new DemoEntities();
Interwiers objInterwiers = new Interwiers();
objInterwiers.Email = "aman@gmail.com";
db.Interwiers.Add(objInterwiers);
db.SaveChanges();现在,如果在表中设置id字段,则不需要在这里输入id字段。
保存数据后,您可以获得id如下:
var id = objInterwiers.Id;这是最近增加的。
你这样做是为了重新引导你想要的
return Redirect("/Interwier/Welcome/"+id);控制器中的整个代码将类似于:
public ActionResult TestSaveData()
{
DemoEntities db = new DemoEntities(); // your entity name
Interwiers objInterwiers = new Interwiers(); //table name
objInterwiers.Email = aman@gmail.com;
db.Interwiers.Add(objInterwiers);
db.SaveChanges();
return RedirectToAction("/Interwier/Welcome/"+id);
}发布于 2017-03-24 09:06:18
默认路由值设置为{控制器}/{action}/{id}。生成链接时,可以使用routeValues设置id。例如。如果链接是从控制器操作生成的,则
public ActionResult MyAction()
{
//code
Return RedirectToAction("Welcome", "Interview", new{InterviewId = Interview.InterviewId});
}这将导致URL localhost:portNumber/Interview/Welcome/InterviewId
https://stackoverflow.com/questions/42995075
复制相似问题