所以我在做什麼看起來很簡單,但我不知道如何去做。如何將UserId添加到ASP.NET MVC中登錄用戶的發佈數據4
我已經註冊並使用帳戶登錄(我正在使用ASP.NET MVC 4中使用的默認成員系統),所以我想將我的UserId添加到我插入數據庫的一些數據中。
這是我在插入數據的模型:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Reroute.Models
{
public class Request
{
public int RequestId { get; set; }
// I want to add UserId based on my current session
public int UserId { get; set; }
public string OrderNumber { get; set; }
public string TrackingNumber { get; set; }
public string CurrentAddress { get; set; }
public string NewAddress { get; set; }
public string Comment { get; set; }
}
}
而且ActionResult的(這裏的地方我認爲我必須做出改變):
[HttpPost]
public ActionResult Create(Request collection)
{
try
{
_db.Requests.Add(collection);
_db.SaveChanges();
//return RedirectToAction("Index");
return Content("Done! Added to DB");
}
catch
{
return View();
}
}
感謝
你對登錄什麼機制?你在使用'FormsAuthentication'類嗎? –
你面臨什麼問題/障礙? –
@vonv。是的,FormsAuthentication – Danny