Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 保存当前用户ID ASP_.net_Entity Framework - Fatal编程技术网

.net 保存当前用户ID ASP

.net 保存当前用户ID ASP,.net,entity-framework,.net,Entity Framework,我是ASP新手,我想知道当当前用户想要进行“预订”时,如何保存该用户 下面是用户的AuthController public class AuthController : Controller { public ActionResult Login() { return View(); } [HttpPost] public ActionResult Login(Cliente cl

我是ASP新手,我想知道当当前用户想要进行“预订”时,如何保存该用户

下面是用户的AuthController

public class AuthController : Controller
    {
        public ActionResult Login()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Login(Cliente cliente, string ReturnUrl)
        {
            if (IsValid(cliente))
            {
                FormsAuthentication.SetAuthCookie(cliente.Rut_Cliente, false);
                if(ReturnUrl != null)
                {
                    return Redirect(ReturnUrl);
                }
                Session["username"] = cliente.Rut_Cliente;
                return RedirectToAction("Index", "Home");
            }
            TempData["mensaje"] = "Nombre o usuario Incorrectos";
            return View(cliente);
                
        }

        private bool IsValid(Cliente cliente)
        {
            return cliente.Autenticar();
        }

        public ActionResult LogOut ()
        {
            FormsAuthentication.SignOut();
            return RedirectToAction("Index", "Home");
        }
    }
以下是ReservaController:

public ActionResult Index()
        {
            ViewBag.reserva = new Reserva().ReadAll();
            return View();
        }

        // GET: Reserva/Details/5
        public ActionResult Details(int id)
        {
            return View();
        }

        // GET: Reserva/Create
        public ActionResult Create()
        {
            EnviarCliente();
            return View();
        }

        private void EnviarCliente()
        {
            ViewBag.cliente = new Cliente().ReadAll();
        }

        // POST: Reserva/Create
        [HttpPost]
        public ActionResult Create([Bind(Include = "Id, Fecha_Inicio, Fecha_Fin, Estado, Cliente_Id")]Reserva reserva)
        {
            try
            {
                // TODO: Add insert logic here
                reserva.Save();
                TempData["mensaje"] = "Guardado correctamente";
                return RedirectToAction("Index");
            }
            catch
            {
                return View(reserva);
            }
        }
如果我在视图中使用DropDownListFor并选择它工作的用户,但我希望使用当前登录的用户ID执行此操作,并且不使用DropDownListFor

以下是“客户Id”是ForeignKey的视图

/*@Html.LabelFor(r => r.Cliente_Id, "Cliente")
    @Html.DropDownListFor(r => r.Cliente_Id, new SelectList(ViewBag.cliente, "Id", "Nombre"))
    <br />*/

    @Html.LabelFor(r => r.Fecha_Inicio, "Fecha Inicial")
    @Html.TextBoxFor(r => r.Fecha_Inicio, new { type = "date" })
    <br />
    @Html.LabelFor(r => r.Fecha_Fin, "Fecha Termino")
    @Html.TextBoxFor(r => r.Fecha_Fin, new { type = "date" })
/*@Html.LabelFor(r=>r.Cliente\u Id,“Cliente”)
@DropDownListFor(r=>r.Cliente_Id,新选择列表(ViewBag.Cliente,“Id”,“Nombre”))

*/ @LabelFor(r=>r.Fecha_Inicio,“Fecha Inicial”) @TextBoxFor(r=>r.Fecha_Inicio,new{type=“date”})
@LabelFor(r=>r.Fecha_Fin,“Fecha Termino”) @TextBoxFor(r=>r.Fecha_Fin,new{type=“date”})
我想使用HiddenFor,但我不知道这是否真的有效